This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients rhettinger
Date 2019-04-04.01:04:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1554339855.64.0.463077014069.issue36521@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2019-04-04 01:04:15rhettingersetrecipients: + rhettinger
2019-04-04 01:04:15rhettingersetmessageid: <1554339855.64.0.463077014069.issue36521@roundup.psfhosted.org>
2019-04-04 01:04:15rhettingerlinkissue36521 messages
2019-04-04 01:04:15rhettingercreate