[issue36906] Compile time textwrap.dedent() equivalent for str or bytes literals

Steven D'Aprano report at bugs.python.org
Mon May 20 11:26:36 EDT 2019


Steven D'Aprano <steve+python at pearwood.info> added the comment:

> One issue with it is that in:
> def f():
>     return "   foo".dedent()
> f will have both "   foo" and "foo" in its constants even if the first is not used anymore.

That seems to be what happens with other folded constants:

py> def f():
...     return 99.0 + 0.9
...
py> f.__code__.co_consts
(None, 99.0, 0.9, 99.9)

so I guess that this is okay for a first draft. One difference is that 
strings tend to be much larger than floats, so this will waste more 
memory. We ought to consider removing unused constants at some point.

(But not me, sorry, I don't have enough C.)

> Removing it requires looping over the code once more while marking 
> the constants seen in a set and I was not sure if this was ok.

That should probably be a new issue.

----------

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


More information about the Python-bugs-list mailing list