-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Public C API for accessing code object fields #94936
Comments
Mucho bueno indeed :) I am willing to consider it but how many new APIs are we talking about? Also, we should double check and agree that exposing these fields is not going to backfire on us if we decide to change the implementation or add new stuff that will invalidate the meaning of the current fields. Maybe we can consider adding them with prefixed underscores (probably a bad idea)? |
3 getter functions. I've thought about whether they will restrict our code. Thing is we already are restricted because all three are already exposed as Python properties. So we have no choice but to maintain backwards compatiblity, even without the new C API changes. |
Calling If performance is the issue, we should offer a faster API (for 3.12) We should also offer the same API in Python. |
Not only that, but def f(a, b):
c = a + b
def d():
return c
return d def g(a, b):
c = a + b
def d():
return a + b
return d
|
Yeah I planned to lazily create the introspection information and cache them there (kind of like how debug information in frames are lazily created). However, that missed that for 3.11 so it should go in 3.12. Something like
|
Given that the user requesting this is writing a profiler and needs access to the frame as well, why not just recommend that they include internal headers and call In the past I think we would never have considered such a late request for new APIs a blocker. |
OK. I'll remove the blocker. However, I think we should consider adding a performant version of these APIs in 3.12. |
After reading the discussion, I concur with Guido. I am removing the 3.11 label. This feature can only be considered from 3.12 onwards. |
See also #91248 |
…honGH-95008) (cherry picked from commit 42b102b) Co-authored-by: Ken Jin <[email protected]>
(cherry picked from commit 42b102b) Co-authored-by: Ken Jin <[email protected]>
Docs TODO. |
What more docs do you need? |
Woops I forgot that I already documented these. Sorry 😆 . I'll leave this issue open for the next thing I plan to do in 3.12:
|
IMO the problem of migrating existing C extensions to Python 3.11 is now solved. What's New in Python 3.11:
I close the issue.
Please open a separated issue for that. |
`python-qt` v. 3.3.0 wasn't compatible with Python 3.11 yet (it contained include statements for header files that were removed by 3.11 [1] and used a python tuple field that was replaced through a dedicated getter function [2]). Switching to version 3.4.2 also means we can remove the `remove-unneeded-pydebug-include.patch`, as it has since been merged. [1]: https://docs.python.org/3.11/whatsnew/3.11.html > The non-limited API files cellobject.h, classobject.h, code.h, context.h, > funcobject.h, genobject.h and longintrepr.h have been moved to the Include/cpython > directory. Moreover, the eval.h header file was removed. These files must not be > included directly, as they are already included in Python.h: Include Files. > If they have been included directly, consider including Python.h instead. [2]: python/cpython#94936 (comment)
A user/maintainer of a popular library documented their use case for accessing fields in the code object. In 3.11 the fields in C are gone but still available as properties in Python. Accessing these properties can be made faster by exposing their functions in the C API. The current option is
PyObject_GetAttrString(code, "attr")
which is much slower.https://discuss.python.org/t/getting-the-class-name-of-a-code-frame-object-in-cpython-3-11-c-api/17396
A similar issue is #92154.
I am marking this as a release blocker @pablogsal as it would be mucho bueno if we could get this before rc1.
The text was updated successfully, but these errors were encountered: