Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 42d9e1b

Browse files
committed
Doc fixes for Argument Clinic.
1 parent d58831e commit 42d9e1b

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

Doc/howto/clinic.rst

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,15 @@ Optional groups are groups of arguments that must all be passed in together.
626626
They can be to the left or the right of the required arguments. They
627627
can *only* be used with positional-only parameters.
628628

629+
.. note:: Optional groups are *only* intended for use when converting
630+
functions that make multiple calls to :c:func:`PyArg_ParseTuple`!
631+
Functions that use *any* other approach for parsing arguments
632+
should *almost never* be converted to Argument Clinic using
633+
optional groups. Functions using optional groups currently
634+
cannot have accurate sigantures in Python, because Python just
635+
doesn't understand the concept. Please avoid using optional
636+
groups wherever possible.
637+
629638
To specify an optional group, add a ``[`` on a line by itself before
630639
the parameters you wish to group together, and a ``]`` on a line by itself
631640
after these parameters. As an example, here's how ``curses.window.addch``
@@ -1278,9 +1287,8 @@ a ``type`` argument to the object converter for ``METH_O``.
12781287
tp_new and tp_init functions
12791288
----------------------------------------------
12801289

1281-
You can convert ``tp_new`` and ``tp_init``
1282-
functions. Just name them ``__new__`` or
1283-
``__init__`` as appropriate. Notes:
1290+
You can convert ``tp_new`` and ``tp_init`` functions. Just name
1291+
them ``__new__`` or ``__init__`` as appropriate. Notes:
12841292

12851293
* The function name generated for ``__new__`` doesn't end in ``__new__``
12861294
like it would by default. It's just the name of the class, converted
@@ -1290,9 +1298,13 @@ functions. Just name them ``__new__`` or
12901298

12911299
* ``__init__`` functions return ``int``, not ``PyObject *``.
12921300

1293-
* Argument Clinic supports any signature for these functions, even though
1294-
the parsing function is required to always take ``args`` and ``kwargs``
1295-
objects.
1301+
* Use the docstring as the class docstring.
1302+
1303+
* Although ``__new__`` and ``__init__`` functions must always
1304+
accept both the ``args`` and ``kwargs`` objects, when converting
1305+
you may specify any signature for these functions that you like.
1306+
(If your function doesn't support keywords, the parsing function
1307+
generated will throw an exception if it receives any.)
12961308

12971309
The #ifdef trick
12981310
----------------------------------------------

0 commit comments

Comments
 (0)