-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
gh-141004: Document missing PyCFunction* and PyCMethod* APIs
#141253
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
Open
ZeroIntensity
wants to merge
6
commits into
python:main
Choose a base branch
from
ZeroIntensity:document-pycfunction-pycmethod
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+94
−0
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1f8d65e
Document missing PyCFunction APIs.
ZeroIntensity a0cf7ec
Document missing PyCMethod APIs.
ZeroIntensity 4ac3cf6
Apply suggestion from @picnixz
ZeroIntensity e059d66
"f" -> "op"
ZeroIntensity ed05eba
Clarify behavior of GET* vs Get*
ZeroIntensity 7bf86c7
Clarify behavior for modules.
ZeroIntensity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -447,6 +447,25 @@ definition with the same method name. | |
| slot. This is helpful because calls to PyCFunctions are optimized more | ||
| than wrapper object calls. | ||
|
|
||
|
|
||
| .. c:var:: PyTypeObject PyCMethod_Type | ||
|
|
||
| The type object corresponding to Python C method objects. This is | ||
| available as :class:`types.BuiltinMethodType` in the Python layer. | ||
|
|
||
|
|
||
| .. c:function:: int PyCMethod_Check(PyObject *op) | ||
|
|
||
| Return true if *op* is an instance of the :c:type:`PyCMethod_Type` type | ||
| or a subtype of it. This function always succeeds. | ||
|
|
||
|
|
||
| .. c:function:: int PyCMethod_CheckExact(PyObject *op) | ||
|
|
||
| This is the same as :c:func:`PyCMethod_Check`, but does not account for | ||
| subtypes. | ||
|
|
||
|
|
||
| .. c:function:: PyObject * PyCMethod_New(PyMethodDef *ml, PyObject *self, PyObject *module, PyTypeObject *cls) | ||
|
|
||
| Turn *ml* into a Python :term:`callable` object. | ||
|
|
@@ -472,6 +491,24 @@ definition with the same method name. | |
| .. versionadded:: 3.9 | ||
|
|
||
|
|
||
| .. c:var:: PyTypeObject PyCFunction_Type | ||
|
|
||
| The type object corresponding to Python C function objects. This is | ||
| available as :class:`types.BuiltinFunctionType` in the Python layer. | ||
|
|
||
|
|
||
| .. c:function:: int PyCFunction_Check(PyObject *op) | ||
|
|
||
| Return true if *op* is an instance of the :c:type:`PyCFunction_Type` type | ||
| or a subtype of it. This function always succeeds. | ||
|
|
||
|
|
||
| .. c:function:: int PyCFunction_CheckExact(PyObject *op) | ||
|
|
||
| This is the same as :c:func:`PyCFunction_Check`, but does not account for | ||
| subtypes. | ||
|
|
||
|
|
||
| .. c:function:: PyObject * PyCFunction_NewEx(PyMethodDef *ml, PyObject *self, PyObject *module) | ||
|
|
||
| Equivalent to ``PyCMethod_New(ml, self, module, NULL)``. | ||
|
|
@@ -482,6 +519,63 @@ definition with the same method name. | |
| Equivalent to ``PyCMethod_New(ml, self, NULL, NULL)``. | ||
|
|
||
|
|
||
| .. c:function:: int PyCFunction_GetFlags(PyObject *func) | ||
|
|
||
| Get the function's flags on *func* as they were passed to | ||
| :c:member:`~PyMethodDef.ml_flags`. | ||
|
|
||
| If *func* is not a C function object, this fails with a | ||
| :class:`SystemError`. | ||
|
|
||
| This function returns the function's flags on success, and ``-1`` with an | ||
| exception set on failure. | ||
|
|
||
|
|
||
| .. c:function:: int PyCFunction_GET_FLAGS(PyObject *func) | ||
|
|
||
| This is the same as :c:func:`PyCFunction_GetFlags`, but without error | ||
| or type checking. | ||
|
|
||
|
|
||
| .. c:function:: PyCFunction PyCFunction_GetFunction(PyObject *func) | ||
|
|
||
| Get the function pointer on *func* as it was passed to | ||
picnixz marked this conversation as resolved.
Show resolved
Hide resolved
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please indicate whether passing a non-function object sets an exception or causes a crash (to make the distinction with |
||
| :c:member:`~PyMethodDef.ml_meth`. | ||
|
|
||
| If *func* is not a C function object, this fails with a | ||
| :class:`SystemError`. | ||
|
|
||
| This function returns the function pointer on success, and ``NULL`` with an | ||
| exception set on failure. | ||
|
|
||
|
|
||
|
|
||
| .. c:function:: int PyCFunction_GET_FUNCTION(PyObject *func) | ||
|
|
||
| This is the same as :c:func:`PyCFunction_GetFunction`, but without error | ||
| or type checking. | ||
|
|
||
|
|
||
| .. c:function:: PyObject *PyCFunction_GetSelf(PyObject *func) | ||
|
|
||
| Get the "self" object on *func*. This is the object that would be passed | ||
picnixz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| to the first argument of a :c:type:`PyCFunction`. For C function objects | ||
| created through a :c:type:`PyMethodDef` on a :c:type:`PyModuleDef`, this | ||
| is the resulting module object. | ||
|
|
||
| If *func* is not a C function object, this fails with a | ||
| :class:`SystemError`. | ||
|
|
||
| This function returns a :term:`borrowed reference` to the "self" object | ||
| on success, and ``NULL`` with an exception set on failure. | ||
|
|
||
|
|
||
| .. c:function:: PyObject *PyCFunction_GET_SELF(PyObject *func) | ||
|
|
||
| This is the same as :c:func:`PyCFunction_GetSelf`, but without error or | ||
| type checking. | ||
|
|
||
|
|
||
| Accessing attributes of extension types | ||
| --------------------------------------- | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This one is a regular exception right? so no need to mention it. What I wanted to know is whether passing
func == NULLproduced a SIGSEGV or a Python exception. Since passing NULL is "allowed" (but raises an exception) it's fine to remove the mention to SystemError.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.
My advice is: check other
Checkfunctions to see how we formulate this. I don't want to be too pedantic but I want to be consistent in general.