Visitar URL original
bpo-42048: Document AC's defining_class converter by erlend-aasland · Pull Request #23978 · python/cpython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-42048: Document AC's defining_class converter
  • Loading branch information
Erlend E. Aasland
Erlend E. Aasland committed Dec 28, 2020
commit c5083652ad1ba10d4d1703b42ba6674409aab6fc
35 changes: 35 additions & 0 deletions Doc/howto/clinic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,41 @@ type for ``self``, it's best to create your own converter, subclassing
[clinic start generated code]*/


Using a "defining class" converter
----------------------------------

Argument Clinic facilitates gaining access to the defining class of a method.
This is useful for heap type methods that need to fetch module level state.
Example from `Modules/zlibmodule.c`::

/*[clinic input]
zlib.Compress.compress

cls: defining_class
data: Py_buffer
/
...
[clinic start generated code]*/
static PyObject *
zlib_Compress_compress_impl(...)
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated
/*[clinic end generated code ...]*/
{
zlibstate *state = PyType_GetModuleState(cls)


Each method may only have one argument using this converter, and it must appear
after `self`, or, if `self` is not used, as the first argument. The argument
will be of type `PyTypeObject *`.

When used, Argument Clinic will select `METH_FASTCALL | METH_KEYWORDS |
METH_METHOD` as the calling convention. The argument will not appear in
`__text_signature__`.

The `defining_class` converter is not compatible with `__init__` and `__new__`
methods, which cannot use the `METH_METHOD` convention.

See also PEP 573.
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated


Writing a custom converter
--------------------------
Expand Down