-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C API] Move the PyCodeObject structure to the internal C API (make the structure opaque) #91397
Comments
The PyCodeObject structure is documented at: The structured evolved a lot in Python 3.11 to optimize Python/ceval.c performance:
New members:
The PyCodeObject structure should be made opaque in the public C API and only accessed with function calls. In Python 3.11, the PyFrameObject structure was made opaque (bpo-46836) and multiple getters were added (bpo-40421). The idea is similar, but it might be too late to do that in Python 3.11 (beta1 feature freeze is close). --- By the way, it was proposed multiple times on python-dev to mark the PyCode_New() function as "unstable" since its API changed often. PEP-670 "Python Positional-Only Parameters" caused a lot of troubles in Cython when it added a new parameter to PyCode_New(). The change was reverted: instead, a new PyCode_NewWithPosOnlyArgs() function was added.
On Python 3.11a1 and newer, Cython uses the code.replace() method (added to Python 3.8) to build new code objects. Otherwise, it just calls directly PyCode_New(). |
See the semi-stable API: |
On nedbat/coveragepy#1353 (comment), @Fidget-Spinner wrote:
It would be nice to add a public C API getter function, something like PyCode_GetCode() which would return a strong reference to a bytes object. |
Ah, @Fidget-Spinner opened #92154 for that! |
Cython issue related to PyCodeObject structure size in Python 3.11: cython/cython#4827 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: