Message339422
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 |
|
Date |
User |
Action |
Args |
2019-04-04 01:04:15 | rhettinger | set | recipients:
+ rhettinger |
2019-04-04 01:04:15 | rhettinger | set | messageid: <1554339855.64.0.463077014069.issue36521@roundup.psfhosted.org> |
2019-04-04 01:04:15 | rhettinger | link | issue36521 messages |
2019-04-04 01:04:15 | rhettinger | create | |
|