You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Code object creation (const interning) can mutate tuples #121954
In #121863 (comment), Mark suspected something is off in const interning for code objects. Indeed, there is. For example:
# a bit of setupimportsysinterned=sys.intern("foobar")
deff():
var="foobar"# my_tuple = (None, 'foobar'), but with an un-interned stringmy_tuple= (None, str(b'foobar', 'ascii'))
print(id(my_tuple), id(my_tuple[1]))
# pass my_tuple as an input argument for a new code objectf.__code__.replace(co_consts=my_tuple)
# there's now a different object in the tuple!print(id(my_tuple), id(my_tuple[1]))
I'm working on a change to:
create new tuples instead of mutating old ones
intern more strings before passing them to PyCode constructors, so that we usually don't need to create new tuples
Activity