You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Code objects, function objects and generator object contain quite a lot of redundant information #100719
There is a quite a lot of redundancy in code, function and generator objects.
Intra-object redundancy
Code objects have four fields ,co_nlocalsplus, co_nplaincellvars, co_nlocals, co_nfreevars. Any of these fields can be computed from the other three.
Code objects have a qualified name and a name. The name is always the suffix of the qualified name. Changing this to qualifying prefix and name would save space and allow sharing.
The defaults and keyword defaults for a function are separate and the keyword defaults are a dict. They could be combined into a single array.
Generator objects have a gi_code field, which is redundant, as the frame contains a reference to the code object.
Inter-object redundancy
Functions and generators have qualified name and name fields, which are almost always the same as the underlying code object. These should be lazily initialized
I have no opinion on whether these changes are good or bad, but they are surely breaking changes. Code objects aren't well documented, but they're not private implementation details. How do you plan to manage these changes?
Activity
stevendaprano commentedon Jan 4, 2023
I have no opinion on whether these changes are good or bad, but they are surely breaking changes. Code objects aren't well documented, but they're not private implementation details. How do you plan to manage these changes?
markshannon commentedon Jan 4, 2023
The
PyCodeObjectstruct is in theInclude/cpythonfolder. So while it is not entirely private, we are allowed to change it.GH-100719: Remove the `co_nplaincellvars` field from code objects. (G…
GH-100719: Remove redundant `gi_code` field from generator object. (G…
terryjreedy commentedon Mar 13, 2023
@stevendaprano The python-level doc for 'internal types', including code objects, https://docs.python.org/3/reference/datamodel.html#codeobject says
'co_nplaincellvars' is not even mentioned in the 3.11 docs.
generator objects are not listed here and their internal gi_xxx methods, as opposed to
__next__, send, and throw, are not indexed.pythonGH-100719: Remove redundant `gi_code` field from generator obje…