Issue34208
Created on 2018-07-24 14:21 by opstad, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Messages (2) | |||
|---|---|---|---|
| msg322304 - (view) | Author: Dave Opstad (opstad) | Date: 2018-07-24 14:21 | |
In 3.6 I get this: >>> x = (100 * 20) >>> x is 2000 False >>> (100 * 20) is 2000 False But in 3.7, I get this: >>> x = (100 * 20) >>> x is 2000 False >>> (100 * 20) is 2000 True This isn't necessarily a problem, but I'm curious why this behavior changed from 3.6 to 3.7. |
|||
| msg322306 - (view) | Author: Eryk Sun (eryksun) * ![]() |
Date: 2018-07-24 14:47 | |
Please refrain from using the issue tracker to satisfy your curiosity. This is a question about compiler optimizations that should be asked on python-list, or maybe python-dev.
You can use the dis module to get a superficial answer in terms of the constants in the code object.
3.6:
>>> dis.dis('(100 * 20) is 2000')
1 0 LOAD_CONST 3 (2000)
2 LOAD_CONST 2 (2000)
4 COMPARE_OP 8 (is)
6 RETURN_VALUE
3.7:
>>> dis.dis('(100 * 20) is 2000')
1 0 LOAD_CONST 0 (2000)
2 LOAD_CONST 0 (2000)
4 COMPARE_OP 8 (is)
6 RETURN_VALUE
The argument of the LOAD_CONST opcode is the index of the constant in the code object's co_consts tuple. In 3.6 you can see it's separate int objects, but in 3.7 the operation uses the same int object (index 0).
|
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:03 | admin | set | github: 78389 |
| 2018-07-24 14:47:54 | eryksun | set | status: open -> closed nosy:
+ eryksun resolution: not a bug |
| 2018-07-24 14:21:42 | opstad | create | |
