This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Dennis Sweeney
Recipients Dennis Sweeney, garylitvin
Date 2021-02-07.05:40:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1612676426.18.0.189903759139.issue43151@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2021-02-07 05:40:26Dennis Sweeneysetrecipients: + Dennis Sweeney, garylitvin
2021-02-07 05:40:26Dennis Sweeneysetmessageid: <1612676426.18.0.189903759139.issue43151@roundup.psfhosted.org>
2021-02-07 05:40:26Dennis Sweeneylinkissue43151 messages
2021-02-07 05:40:25Dennis Sweeneycreate