> 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. |