-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why? a is b #100
Comments
Let me dig deeper to check what changed in Python 3.7 that's causing this. |
Python 3.7.1 (default, Dec 7 2018, 14:57:25)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a,b = 257,257
>>> a is b
False
>>> a = 257
>>> b = 257
>>> a is b
False
>>> a = 257 ; b = 257
>>> a is b
True |
But if using Python 3.7.1 (default, Nov 24 2018, 22:14:32) [MSC v.1912 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a, b = 257, 257
>>> a is b
False
>>> a, b = int(257), int(257)
>>> a is b
True |
|
Let me give a summary for the first example "Strings can be tricky sometimes *". >>> a, b = "wtf!", "wtf!'
>>> a is b
True # in Python < 3.7
False # in Python >= 3.7
>>> 'a' * 20 is 'aaaaaaaaaaaaaaaaaaaa'
True # in all Python versions
>>> 'a' * 21 is 'aaaaaaaaaaaaaaaaaaaaa'
False # in Python < 3.7
True # in Python >= 3.7 |
Python 3.7.3 (default, Mar 27 2019, 09:23:39)
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a, b = 257, 257
>>> a is b
False
>>> a = 257; b = 257;
>>> a is b
True
>>> a, b = int(257), int(257)
>>> a is b
True
>>> a = 257
>>> b = 257
>>> a is b
False |
Okay, to summarize >>> a, b = 257, 257
>>> a is b
True # Python 3.6 or less
False # Python 3.7
>>> a = 257; b =257;
>>> a is b
False # Python 3.6 or less
True # Python 3.7 I tried disassembling the code, but couldn't find the reason for this difference
LOAD_CONST is being called only once in both the cases. Any help in figuring out the exact change which led to this difference is appreciated 😅 |
Similar results come when we replace |
Update: Just realized even Python 3.8 has Python 3.6 like behavior, it was only 3.7 that behaving this way. >>> a, b = 257, 257
>>> a is b
True # Python 3.6 or less or 3.8+
False # Python 3.7
>>> a = 257; b =257;
>>> a is b
False # Python 3.6 or less or 3.8+
True # Python 3.7 Diving into 3.8 changelog to figure out what changed... |
Hi! Thanks for the nice repo! I've noticed one thing: $ python3.8
Python 3.8.0 (default, Nov 3 2019, 18:06:07)
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = "str1"
>>> b = "str1"
>>> a is b
True
>>> a = "str!"
>>> b = "str!"
>>> a is b
False
>>> a, b = "str!", "str!"
>>> a is b
True
>>> exit()
$ cat script.py
a = "str1"
b = "str1"
print(a is b)
a = "str!"
b = "str!"
print (a is b)
a, b = "str!", "str!"
print(a is b)
$ python3.8 script.py
True
True
True Just interesting, does it mean that default optimizations for main and script are different? |
Hey, yes. I added a small note regarding this (will publish in next revision), but here's the gist,
|
a, b = "wtf!", "wtf!" In Python 3.7.5, Did I miss something? |
Out of curiosity I bisected this and found out, that this commit caused the regression in CPython 3.7: This relates to this ticket on bpo: https://bugs.python.org/issue29469 Edit: The original behaviour was restored with this commit: This was triggered by the ticket https://bugs.python.org/issue34100. |
python: 3.7.1
The text was updated successfully, but these errors were encountered: