-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
gh-92154: Expose PyCode_GetCode in the C API #92168
Conversation
Objects/codeobject.c
Outdated
PyCode_GetCode(PyObject *co) | ||
{ | ||
if (!PyCode_Check(co)) { | ||
PyErr_BadInternalCall(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot if this or a TypeError
is preferred for the C API (or no error setting at all?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use PyCode_GetCode(PyCodeObject *co)
and then you won't need the check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to, but co_code
was previously PyObject*
, and I want this to be a drop-in replacement as far as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PyErr_BadInternalCall() is fine, but I would even suggest replacing a runtime check with an assertion. The caller is responsible to pass the right type.
Also I frankly have no clue if we need to update |
Objects/codeobject.c
Outdated
PyCode_GetCode(PyObject *co) | ||
{ | ||
if (!PyCode_Check(co)) { | ||
PyErr_BadInternalCall(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PyErr_BadInternalCall() is fine, but I would even suggest replacing a runtime check with an assertion. The caller is responsible to pass the right type.
Include/cpython/ is the API excluded from the limited C API and so excluded from the stable ABI: https://devguide.python.org/c-api/ Please don't add this function to the stable ABI yet. Let's wait for one Python release, and then see if it's stable or not. |
I prepared PR python/pythoncapi-compat#34 to add the function to pythoncapi-compat. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Fixes #92154.