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 steven.daprano
Recipients Kay.Hayen, steven.daprano
Date 2016-09-02.17:19:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1472836790.28.0.751403597074.issue27942@psf.upfronthosting.co.za>
In-reply-to
Content
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?
History
Date User Action Args
2016-09-02 17:19:50steven.dapranosetrecipients: + steven.daprano, Kay.Hayen
2016-09-02 17:19:50steven.dapranosetmessageid: <1472836790.28.0.751403597074.issue27942@psf.upfronthosting.co.za>
2016-09-02 17:19:50steven.dapranolinkissue27942 messages
2016-09-02 17:19:50steven.dapranocreate