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
Default value identity regression #72129
Comments
Consider this: def defaultKeepsIdentity(arg = "str_value"):
print(arg is "str_value")
defaultKeepsIdentity() This has been outputing "True" on every Python release I have seen so far, but not so on 3.6.0a4. Normally string values come from a "co_const" and will be "is" identical if used as literals in a module, but no longer in this case. This seems wasteful at best, needlessly increasing the number of strings in usage. Yours, |
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 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? |
Same with 3.6b1, still present. |
It would be nice to get this fixed. |
New changeset 78bea78d9335 by Serhiy Storchaka in branch '3.5': New changeset 0ce63a7651b9 by Serhiy Storchaka in branch '3.6': New changeset 44af6bd21b94 by Serhiy Storchaka in branch 'default': New changeset 7cea3bf44acb by Serhiy Storchaka in branch '2.7': |
Thanks Naoki and Josh for reviews. Backported to 2.7 and 3.5 since the patch also fixes other issues. Note that the result of |
The patch is causing refleaks:
Please review the attached patch fixing that. Please review. |
Looks like the attached patch also fixes test_trace leaked [12, 12, 12] references, sum=36 |
Good catch! The patch LGTM, thanks Yury. Interesting, what tests in test_ast leak? I expected that this branch is executed in rare circumstances. |
The test that tests it all :) test_stdlib_validates |
New changeset 41613bb27f80 by Yury Selivanov in branch '2.7': New changeset 2c6825c9ecfd by Yury Selivanov in branch '3.5': New changeset b671ac7ae620 by Yury Selivanov in branch '3.6': New changeset c27269c0d619 by Yury Selivanov in branch 'default': |
Thanks for the review, Serhiy! |
:) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: