@@ -149,7 +149,7 @@ Let's dive in!
149
149
1. Find a Python builtin that calls either :c:func: `PyArg_ParseTuple `
150
150
or :c:func: `PyArg_ParseTupleAndKeywords `, and hasn't been converted
151
151
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() ``.
153
153
154
154
2. If the call to the ``PyArg_Parse `` function uses any of the
155
155
following format units::
@@ -214,7 +214,7 @@ Let's dive in!
214
214
Sample::
215
215
216
216
/*[clinic input]
217
- pickle .Pickler.dump
217
+ _pickle .Pickler.dump
218
218
219
219
Write a pickled representation of obj to the open file.
220
220
[clinic start generated code]*/
@@ -227,22 +227,27 @@ Let's dive in!
227
227
the top. (In our sample code we'll just show the two blocks next to
228
228
each other.)
229
229
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
+
230
238
Sample::
231
239
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]*/
236
244
237
- /*[clinic input]
238
- pickle .Pickler.dump
245
+ /*[clinic input]
246
+ _pickle .Pickler.dump
239
247
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]*/
242
250
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.
246
251
247
252
248
253
@@ -286,13 +291,13 @@ Let's dive in!
286
291
287
292
Sample::
288
293
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]*/
293
298
294
- /*[clinic input]
295
- pickle .Pickler.dump
299
+ /*[clinic input]
300
+ _pickle .Pickler.dump
296
301
297
302
obj: 'O'
298
303
@@ -309,7 +314,7 @@ Let's dive in!
309
314
itself before the first keyword-only argument, indented the
310
315
same as the parameter lines.
311
316
312
- (``pickle .Pickler.dump `` has neither, so our sample is unchanged.)
317
+ (``_pickle .Pickler.dump `` has neither, so our sample is unchanged.)
313
318
314
319
315
320
10. If the existing C function calls :c:func: `PyArg_ParseTuple `
@@ -327,12 +332,12 @@ Let's dive in!
327
332
Sample::
328
333
329
334
/*[clinic input]
330
- module pickle
331
- class pickle .Pickler
335
+ module _pickle
336
+ class _pickle .Pickler "PicklerObject *" "&Pickler_Type"
332
337
[clinic start generated code]*/
333
338
334
339
/*[clinic input]
335
- pickle .Pickler.dump
340
+ _pickle .Pickler.dump
336
341
337
342
obj: 'O'
338
343
/
@@ -354,12 +359,12 @@ Let's dive in!
354
359
Sample::
355
360
356
361
/*[clinic input]
357
- module pickle
358
- class pickle .Pickler
362
+ module _pickle
363
+ class _pickle .Pickler "PicklerObject *" "&Pickler_Type"
359
364
[clinic start generated code]*/
360
365
361
366
/*[clinic input]
362
- pickle .Pickler.dump
367
+ _pickle .Pickler.dump
363
368
364
369
obj: 'O'
365
370
The object to be pickled.
@@ -373,13 +378,13 @@ Let's dive in!
373
378
the file in your text editor to see::
374
379
375
380
/*[clinic input]
376
- module pickle
377
- class pickle .Pickler
381
+ module _pickle
382
+ class _pickle .Pickler "PicklerObject *" "&Pickler_Type"
378
383
[clinic start generated code]*/
379
384
/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
380
385
381
386
/*[clinic input]
382
- pickle .Pickler.dump
387
+ _pickle .Pickler.dump
383
388
384
389
obj: 'O'
385
390
The object to be pickled.
@@ -388,12 +393,12 @@ Let's dive in!
388
393
Write a pickled representation of obj to the open file.
389
394
[clinic start generated code]*/
390
395
391
- PyDoc_STRVAR(pickle_Pickler_dump__doc__ ,
396
+ PyDoc_STRVAR(_pickle_Pickler_dump__doc__ ,
392
397
"Write a pickled representation of obj to the open file.\n"
393
398
"\n"
394
399
...
395
400
static PyObject *
396
- pickle_Pickler_dump_impl(PyObject *self, PyObject *obj)
401
+ _pickle_Pickler_dump_impl(PicklerObject *self, PyObject *obj)
397
402
/*[clinic end generated code: checksum=3bd30745bf206a48f8b576a1da3d90f55a0a4187]*/
398
403
399
404
Obviously, if Argument Clinic didn't produce any output, it's because
@@ -428,8 +433,8 @@ Let's dive in!
428
433
macro defining the appropriate static :c:type: `PyMethodDef ` structure for
429
434
this builtin::
430
435
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__ },
433
438
434
439
This static structure should be *exactly * the same as the existing static
435
440
:c:type: `PyMethodDef ` structure for this builtin.
@@ -463,13 +468,13 @@ Let's dive in!
463
468
Sample::
464
469
465
470
/*[clinic input]
466
- module pickle
467
- class pickle .Pickler
471
+ module _pickle
472
+ class _pickle .Pickler "PicklerObject *" "&Pickler_Type"
468
473
[clinic start generated code]*/
469
474
/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
470
475
471
476
/*[clinic input]
472
- pickle .Pickler.dump
477
+ _pickle .Pickler.dump
473
478
474
479
obj: 'O'
475
480
The object to be pickled.
@@ -478,12 +483,12 @@ Let's dive in!
478
483
Write a pickled representation of obj to the open file.
479
484
[clinic start generated code]*/
480
485
481
- PyDoc_STRVAR(pickle_Pickler_dump__doc__ ,
486
+ PyDoc_STRVAR(__pickle_Pickler_dump__doc__ ,
482
487
"Write a pickled representation of obj to the open file.\n"
483
488
"\n"
484
489
...
485
490
static PyObject *
486
- pickle_Pickler_dump_impl(PyObject *self, PyObject *obj)
491
+ _pickle_Pickler_dump_impl(PicklerObject *self, PyObject *obj)
487
492
/*[clinic end generated code: checksum=3bd30745bf206a48f8b576a1da3d90f55a0a4187]*/
488
493
{
489
494
/* Check whether the Pickler was initialized correctly (issue3664).
@@ -515,8 +520,8 @@ Let's dive in!
515
520
Sample::
516
521
517
522
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
520
525
{NULL, NULL} /* sentinel */
521
526
};
522
527
@@ -1106,15 +1111,16 @@ Using a "self converter"
1106
1111
------------------------
1107
1112
1108
1113
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
1110
1117
Argument Clinic's converter and specify one yourself.
1111
1118
Just add your own ``self `` parameter as the first parameter in a
1112
1119
block, and ensure that its converter is an instance of
1113
1120
``self_converter `` or a subclass thereof.
1114
1121
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.
1118
1124
1119
1125
How do you specify the custom type you want to cast ``self `` to?
1120
1126
If you only have one or two functions with the same type for ``self ``,
@@ -1502,6 +1508,8 @@ preset configurations, as follows:
1502
1508
and ``docstring_prototype ``, write the ``impl_definition `` to
1503
1509
``block ``, and write everything else to ``file ``.
1504
1510
1511
+ The default filename is ``"{dirname}/clinic/{basename}.h" ``.
1512
+
1505
1513
``buffer ``
1506
1514
Save up all most of the output from Clinic, to be written into
1507
1515
your file near the end. For Python files implementing modules
@@ -1554,7 +1562,7 @@ The ``new`` subcommand works like this::
1554
1562
1555
1563
This creates a new destination with name ``<name> `` and type ``<type> ``.
1556
1564
1557
- There are five destination types::
1565
+ There are five destination types:
1558
1566
1559
1567
``suppress ``
1560
1568
Throws the text away.
@@ -1575,12 +1583,18 @@ There are five destination types::
1575
1583
The template can use three strings internally that will be replaced
1576
1584
by bits of the filename:
1577
1585
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.
1580
1590
{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.
1584
1598
1585
1599
If there are no periods in the filename, {basename} and {filename}
1586
1600
are the same, and {extension} is empty. "{basename}{extension}"
0 commit comments