[issue36521] Consider removing docstrings from co_consts in code objects

Inada Naoki report at bugs.python.org
Fri Sep 3 20:52:02 EDT 2021


Inada Naoki <songofacandy at gmail.com> added the comment:

> I am still not convinced that it's a good idea to put the docstring in the surrounding code object. I'd like to be able to see it when I introspect a code object, not just when introspecting a function object (I may be analyzing code only, and it's hard to connect the code object with the NEW_FUNCTION opcode in the parent code object -- you have to scan the bytecode, which is fragile.)

I think that reasoning is not strong enough to add new member to code object.

* Modules and classes don't get docstring from their code objects. Why only functions need to store docstring?
* Lambdas, comprehensions, and PEP 649 (if acceptted) uses code objects but no docstring. Why they need to pay cost of `co_doc` member? (cost = memory + unmarshal time).

Code objects have filename and firstlineno. And there are many functions without docstring. So removing docstring from code object won't make inspection hard so much.

----------

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


More information about the Python-bugs-list mailing list