Skip to content

Commit 96aca64

Browse files
larryhastingserlend-aasland
authored andcommitted
Documentation fixes, including fixing "suspicious" problems.
1 parent adecaef commit 96aca64

File tree

1 file changed

+64
-50
lines changed

1 file changed

+64
-50
lines changed

Doc/howto/clinic.rst

Lines changed: 64 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Let's dive in!
149149
1. Find a Python builtin that calls either :c:func:`PyArg_ParseTuple`
150150
or :c:func:`PyArg_ParseTupleAndKeywords`, and hasn't been converted
151151
to work with Argument Clinic yet.
152-
For my example I'm using ``pickle.Pickler.dump()``.
152+
For my example I'm using ``_pickle.Pickler.dump()``.
153153

154154
2. If the call to the ``PyArg_Parse`` function uses any of the
155155
following format units::
@@ -214,7 +214,7 @@ Let's dive in!
214214
Sample::
215215

216216
/*[clinic input]
217-
pickle.Pickler.dump
217+
_pickle.Pickler.dump
218218

219219
Write a pickled representation of obj to the open file.
220220
[clinic start generated code]*/
@@ -227,22 +227,27 @@ Let's dive in!
227227
the top. (In our sample code we'll just show the two blocks next to
228228
each other.)
229229

230+
The name of the class and module should be the same as the one
231+
seen by Python. Check the name defined in the :c:type:`PyModuleDef`
232+
or :c:type:`PyTypeObject` as appropriate.
233+
234+
When you declare a class, you must also specify two aspects of its type
235+
in C: the type declaration you'd use for a pointer to an instance of
236+
this class, and a pointer to the :c:type:`PyTypeObject` for this class.
237+
230238
Sample::
231239

232-
/*[clinic input]
233-
module pickle
234-
class pickle.Pickler
235-
[clinic start generated code]*/
240+
/*[clinic input]
241+
module _pickle
242+
class _pickle.Pickler "PicklerObject *" "&Pickler_Type"
243+
[clinic start generated code]*/
236244

237-
/*[clinic input]
238-
pickle.Pickler.dump
245+
/*[clinic input]
246+
_pickle.Pickler.dump
239247

240-
Write a pickled representation of obj to the open file.
241-
[clinic start generated code]*/
248+
Write a pickled representation of obj to the open file.
249+
[clinic start generated code]*/
242250

243-
The name of the class and module should be the same as the one
244-
seen by Python. Check the name defined in the :c:type:`PyModuleDef`
245-
or :c:type:`PyTypeObject` as appropriate.
246251

247252

248253

@@ -286,13 +291,13 @@ Let's dive in!
286291

287292
Sample::
288293

289-
/*[clinic input]
290-
module pickle
291-
class pickle.Pickler
292-
[clinic start generated code]*/
294+
/*[clinic input]
295+
module _pickle
296+
class _pickle.Pickler "PicklerObject *" "&Pickler_Type"
297+
[clinic start generated code]*/
293298

294-
/*[clinic input]
295-
pickle.Pickler.dump
299+
/*[clinic input]
300+
_pickle.Pickler.dump
296301

297302
obj: 'O'
298303

@@ -309,7 +314,7 @@ Let's dive in!
309314
itself before the first keyword-only argument, indented the
310315
same as the parameter lines.
311316

312-
(``pickle.Pickler.dump`` has neither, so our sample is unchanged.)
317+
(``_pickle.Pickler.dump`` has neither, so our sample is unchanged.)
313318

314319

315320
10. If the existing C function calls :c:func:`PyArg_ParseTuple`
@@ -327,12 +332,12 @@ Let's dive in!
327332
Sample::
328333

329334
/*[clinic input]
330-
module pickle
331-
class pickle.Pickler
335+
module _pickle
336+
class _pickle.Pickler "PicklerObject *" "&Pickler_Type"
332337
[clinic start generated code]*/
333338

334339
/*[clinic input]
335-
pickle.Pickler.dump
340+
_pickle.Pickler.dump
336341

337342
obj: 'O'
338343
/
@@ -354,12 +359,12 @@ Let's dive in!
354359
Sample::
355360

356361
/*[clinic input]
357-
module pickle
358-
class pickle.Pickler
362+
module _pickle
363+
class _pickle.Pickler "PicklerObject *" "&Pickler_Type"
359364
[clinic start generated code]*/
360365

361366
/*[clinic input]
362-
pickle.Pickler.dump
367+
_pickle.Pickler.dump
363368

364369
obj: 'O'
365370
The object to be pickled.
@@ -373,13 +378,13 @@ Let's dive in!
373378
the file in your text editor to see::
374379

375380
/*[clinic input]
376-
module pickle
377-
class pickle.Pickler
381+
module _pickle
382+
class _pickle.Pickler "PicklerObject *" "&Pickler_Type"
378383
[clinic start generated code]*/
379384
/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
380385

381386
/*[clinic input]
382-
pickle.Pickler.dump
387+
_pickle.Pickler.dump
383388

384389
obj: 'O'
385390
The object to be pickled.
@@ -388,12 +393,12 @@ Let's dive in!
388393
Write a pickled representation of obj to the open file.
389394
[clinic start generated code]*/
390395

391-
PyDoc_STRVAR(pickle_Pickler_dump__doc__,
396+
PyDoc_STRVAR(_pickle_Pickler_dump__doc__,
392397
"Write a pickled representation of obj to the open file.\n"
393398
"\n"
394399
...
395400
static PyObject *
396-
pickle_Pickler_dump_impl(PyObject *self, PyObject *obj)
401+
_pickle_Pickler_dump_impl(PicklerObject *self, PyObject *obj)
397402
/*[clinic end generated code: checksum=3bd30745bf206a48f8b576a1da3d90f55a0a4187]*/
398403

399404
Obviously, if Argument Clinic didn't produce any output, it's because
@@ -428,8 +433,8 @@ Let's dive in!
428433
macro defining the appropriate static :c:type:`PyMethodDef` structure for
429434
this builtin::
430435

431-
#define _PICKLE_PICKLER_DUMP_METHODDEF \
432-
{"dump", (PyCFunction)_pickle_Pickler_dump, METH_O, _pickle_Pickler_dump__doc__},
436+
#define __PICKLE_PICKLER_DUMP_METHODDEF \
437+
{"dump", (PyCFunction)__pickle_Pickler_dump, METH_O, __pickle_Pickler_dump__doc__},
433438

434439
This static structure should be *exactly* the same as the existing static
435440
:c:type:`PyMethodDef` structure for this builtin.
@@ -463,13 +468,13 @@ Let's dive in!
463468
Sample::
464469

465470
/*[clinic input]
466-
module pickle
467-
class pickle.Pickler
471+
module _pickle
472+
class _pickle.Pickler "PicklerObject *" "&Pickler_Type"
468473
[clinic start generated code]*/
469474
/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
470475

471476
/*[clinic input]
472-
pickle.Pickler.dump
477+
_pickle.Pickler.dump
473478

474479
obj: 'O'
475480
The object to be pickled.
@@ -478,12 +483,12 @@ Let's dive in!
478483
Write a pickled representation of obj to the open file.
479484
[clinic start generated code]*/
480485

481-
PyDoc_STRVAR(pickle_Pickler_dump__doc__,
486+
PyDoc_STRVAR(__pickle_Pickler_dump__doc__,
482487
"Write a pickled representation of obj to the open file.\n"
483488
"\n"
484489
...
485490
static PyObject *
486-
pickle_Pickler_dump_impl(PyObject *self, PyObject *obj)
491+
_pickle_Pickler_dump_impl(PicklerObject *self, PyObject *obj)
487492
/*[clinic end generated code: checksum=3bd30745bf206a48f8b576a1da3d90f55a0a4187]*/
488493
{
489494
/* Check whether the Pickler was initialized correctly (issue3664).
@@ -515,8 +520,8 @@ Let's dive in!
515520
Sample::
516521

517522
static struct PyMethodDef Pickler_methods[] = {
518-
_PICKLE_PICKLER_DUMP_METHODDEF
519-
_PICKLE_PICKLER_CLEAR_MEMO_METHODDEF
523+
__PICKLE_PICKLER_DUMP_METHODDEF
524+
__PICKLE_PICKLER_CLEAR_MEMO_METHODDEF
520525
{NULL, NULL} /* sentinel */
521526
};
522527

@@ -1106,15 +1111,16 @@ Using a "self converter"
11061111
------------------------
11071112

11081113
Argument Clinic automatically adds a "self" parameter for you
1109-
using a default converter. However, you can override
1114+
using a default converter. It automatically sets the ``type``
1115+
of this parameter to the "pointer to an instance" you specified
1116+
when you declared the type. However, you can override
11101117
Argument Clinic's converter and specify one yourself.
11111118
Just add your own ``self`` parameter as the first parameter in a
11121119
block, and ensure that its converter is an instance of
11131120
``self_converter`` or a subclass thereof.
11141121

1115-
What's the point? This lets you automatically cast ``self``
1116-
from ``PyObject *`` to a custom type, just like ``object()``
1117-
does with its ``type`` parameter.
1122+
What's the point? This lets you override the type of ``self``,
1123+
or give it a different default name.
11181124

11191125
How do you specify the custom type you want to cast ``self`` to?
11201126
If you only have one or two functions with the same type for ``self``,
@@ -1502,6 +1508,8 @@ preset configurations, as follows:
15021508
and ``docstring_prototype``, write the ``impl_definition`` to
15031509
``block``, and write everything else to ``file``.
15041510

1511+
The default filename is ``"{dirname}/clinic/{basename}.h"``.
1512+
15051513
``buffer``
15061514
Save up all most of the output from Clinic, to be written into
15071515
your file near the end. For Python files implementing modules
@@ -1554,7 +1562,7 @@ The ``new`` subcommand works like this::
15541562

15551563
This creates a new destination with name ``<name>`` and type ``<type>``.
15561564

1557-
There are five destination types::
1565+
There are five destination types:
15581566

15591567
``suppress``
15601568
Throws the text away.
@@ -1575,12 +1583,18 @@ There are five destination types::
15751583
The template can use three strings internally that will be replaced
15761584
by bits of the filename:
15771585

1578-
{filename}
1579-
The full filename.
1586+
{path}
1587+
The full path to the file, including directory and full filename.
1588+
{dirname}
1589+
The name of the directory the file is in.
15801590
{basename}
1581-
Everything up to but not including the last '.'.
1582-
{extension}
1583-
The last '.' and everything after it.
1591+
Just the name of the file, not including the directory.
1592+
{basename_root}
1593+
Basename with the extension clipped off
1594+
(everything up to but not including the last '.').
1595+
{basename_extension}
1596+
The last '.' and everything after it. If the basename
1597+
does not contain a period, this will be the empty string.
15841598

15851599
If there are no periods in the filename, {basename} and {filename}
15861600
are the same, and {extension} is empty. "{basename}{extension}"

0 commit comments

Comments
 (0)