3 ms·
One of the undocumented oddities of the peephole optimizer is that it will try to merge duplicate constants. When combined with integer (non-)interning, this le
by eesmith 9y ago
One of the undocumented oddities of the peephole optimizer is that it will try to merge duplicate constants. When combined with integer (non-)interning, this lets me do:
>>> a = 300
>>> b = 300
>>> print(a is b)
False
>>> a = 300; b = 300; print(a is b)
True
>>> def my_function():
... a = 300
... b = 300
... print(a is b)
...
>>> my_function()
True
... and I see in the followup posting (this puzzle is from 213) that that was the desired answer, and that it was further analyzed in various ways, and improved upon.
- AstralStorm 9y agoPretty cool. I was thinking about some scoping issue. (Python scoping is very crusty.)