Message274262
Can confirm the expected behaviour (printing True) in Python 2.4 through 2.7, 3.3, Jython 2.5, and even venerable old Python 1.5 (where it prints 1).
But *not* IronPython 2.6, where it prints False.
In 3.6, the difference seems to be here:
py> f = defaultKeepsIdentity
py> f.__defaults__[0] is f.__code__.co_consts[1]
False
py> f.__defaults__[0] == f.__code__.co_consts[1]
True
This behaviour is not specified by the language. Caching and re-use of strings has always been subject to change. Nevertheless, perhaps it is time for this to be make a language feature: inside a function, any use of the same string literal should use the same object? |
|
Date |
User |
Action |
Args |
2016-09-02 17:19:50 | steven.daprano | set | recipients:
+ steven.daprano, Kay.Hayen |
2016-09-02 17:19:50 | steven.daprano | set | messageid: <1472836790.28.0.751403597074.issue27942@psf.upfronthosting.co.za> |
2016-09-02 17:19:50 | steven.daprano | link | issue27942 messages |
2016-09-02 17:19:50 | steven.daprano | create | |
|