[issue36521] Consider removing docstrings from co_consts in code objects
Raymond Hettinger
report at bugs.python.org
Wed Apr 3 21:04:15 EDT 2019
New submission from Raymond Hettinger <raymond.hettinger at gmail.com>:
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 <report at bugs.python.org>
<https://bugs.python.org/issue36521>
_______________________________________
More information about the Python-bugs-list
mailing list