[issue34100] Same constants in tuples are not merged while compile()

INADA Naoki report at bugs.python.org
Tue Nov 27 22:14:00 EST 2018


INADA Naoki <songofacandy at gmail.com> added the comment:

I agree that modifying tuple is bad idea in general case.

But in case of constants, in-place modify is the easiest approach.

Our purpose is "merging" constant.  On the other hand, "build new tuple and
replace old tuple" approach makes two same constant tuples.
If old tuple is referenced from somewhere, we fail to "merging".

So I don't think we need to follow the general principle unless it reduces code.

FYI, we have similar in-place editing for interning already.
https://github.com/python/cpython/blob/master/Objects/codeobject.c#L47-L95

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34100>
_______________________________________


More information about the Python-bugs-list mailing list