Dennis Sweeney <sweeney.dennis...@gmail.com> added the comment:

This was a very intentional change from the commit 
3bcbedc9f1471d957a30a90f9d1251516b422416

It's not safe to check `x is y` when x and y are strings.
You should always use `x == y` for strings instead.
In CPython, if the names x and y both refer to the same underlying object, then 
`x is y` will return True.
In CPython, if the names x and y refer to two distinct string objects with 
equal values, then `x is y` will return False.
Which case happens is an implementation detail, and alternate Python 
implementations like PyPy could behave unexpectedly with such code.
As such, to prevent more incorrect code, this was changed to emit a 
SyntaxWarning in Python 3.8.

This is documented here:
https://docs.python.org/3/whatsnew/3.8.html#changes-in-python-behavior

In a python REPL, I believe SyntaxWarnings are by default promoted to 
SyntaxErrors. But when running a file with `python -Wa`, you just get the 
warning:

$ python -Wa ./a.py
.../a.py:2: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if x is 'a':
a

----------
nosy: +Dennis Sweeney

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43151>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to