New submission from Raymond Hettinger <[email protected]>:
Function objects provide __doc__ as a documented writeable attribute. However,
code objects also have the same information in co_consts[0]. When __doc__ is
changed, the latter keeps a reference to the old string. Also, the disassembly
shows that co_consts[0] is never used. Can we remove the entry in co_consts?
It looks like a compilation artifact rather than something that we need or want.
>>> def f(x):
'y'
>>> f.__doc__
'y'
>>> f.__code__.co_consts[0]
'y'
>>> f.__doc__ = 'z'
>>> f.__code__.co_consts[0]
'y'
>>> from dis import dis
>>> dis(f)
2 0 LOAD_CONST 1 (None)
2 RETURN_VALUE
----------
components: Interpreter Core
messages: 339422
nosy: rhettinger
priority: normal
severity: normal
status: open
title: Consider removing docstrings from co_consts in code objects
type: resource usage
versions: Python 3.8
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36521>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com