Skip to content

Commit 4625826

Browse files
committed
Two minor Argument Clinic bugfixes: use the name of the class in the
docstring for __new__ and __init__, and always use "goto exit" instead of returning "NULL" for failure to parse (as _new__ and __init__ return ints).
1 parent 071baa6 commit 4625826

6 files changed

Lines changed: 32 additions & 25 deletions

File tree

Modules/_cursesmodule.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -621,36 +621,37 @@ curses_window_addch(PyObject *self, PyObject *args)
621621
switch (PyTuple_GET_SIZE(args)) {
622622
case 1:
623623
if (!PyArg_ParseTuple(args, "O:addch", &ch))
624-
return NULL;
624+
goto exit;
625625
break;
626626
case 2:
627627
if (!PyArg_ParseTuple(args, "Ol:addch", &ch, &attr))
628-
return NULL;
628+
goto exit;
629629
group_right_1 = 1;
630630
break;
631631
case 3:
632632
if (!PyArg_ParseTuple(args, "iiO:addch", &x, &y, &ch))
633-
return NULL;
633+
goto exit;
634634
group_left_1 = 1;
635635
break;
636636
case 4:
637637
if (!PyArg_ParseTuple(args, "iiOl:addch", &x, &y, &ch, &attr))
638-
return NULL;
638+
goto exit;
639639
group_right_1 = 1;
640640
group_left_1 = 1;
641641
break;
642642
default:
643643
PyErr_SetString(PyExc_TypeError, "curses.window.addch requires 1 to 4 arguments");
644-
return NULL;
644+
goto exit;
645645
}
646646
return_value = curses_window_addch_impl(self, group_left_1, x, y, ch, group_right_1, attr);
647647

648+
exit:
648649
return return_value;
649650
}
650651

651652
static PyObject *
652653
curses_window_addch_impl(PyObject *self, int group_left_1, int x, int y, PyObject *ch, int group_right_1, long attr)
653-
/*[clinic end generated code: checksum=b073327add8197b6ba7fb96c87062422c8312954]*/
654+
/*[clinic end generated code: checksum=53d44d79791b30950972b3256bdd464f7426bf82]*/
654655
{
655656
PyCursesWindowObject *cwself = (PyCursesWindowObject *)self;
656657
int coordinates_group = group_left_1;

Modules/_dbmmodule.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,25 +300,26 @@ dbm_dbm_get(PyObject *self, PyObject *args)
300300
switch (PyTuple_GET_SIZE(args)) {
301301
case 1:
302302
if (!PyArg_ParseTuple(args, "s#:get", &key, &key_length))
303-
return NULL;
303+
goto exit;
304304
break;
305305
case 2:
306306
if (!PyArg_ParseTuple(args, "s#O:get", &key, &key_length, &default_value))
307-
return NULL;
307+
goto exit;
308308
group_right_1 = 1;
309309
break;
310310
default:
311311
PyErr_SetString(PyExc_TypeError, "dbm.dbm.get requires 1 to 2 arguments");
312-
return NULL;
312+
goto exit;
313313
}
314314
return_value = dbm_dbm_get_impl((dbmobject *)self, key, key_length, group_right_1, default_value);
315315

316+
exit:
316317
return return_value;
317318
}
318319

319320
static PyObject *
320321
dbm_dbm_get_impl(dbmobject *dp, const char *key, Py_ssize_clean_t key_length, int group_right_1, PyObject *default_value)
321-
/*[clinic end generated code: checksum=2c3209571267017f1b9abbd19e1b521849fd5d4a]*/
322+
/*[clinic end generated code: checksum=ca8bf63ec226e71d3cf390749777f7d5b7361478]*/
322323
{
323324
datum dbm_key, val;
324325

Modules/_opcode.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ _opcode_stack_effect(PyModuleDef *module, PyObject *args)
4242
switch (PyTuple_GET_SIZE(args)) {
4343
case 1:
4444
if (!PyArg_ParseTuple(args, "i:stack_effect", &opcode))
45-
return NULL;
45+
goto exit;
4646
break;
4747
case 2:
4848
if (!PyArg_ParseTuple(args, "ii:stack_effect", &opcode, &oparg))
49-
return NULL;
49+
goto exit;
5050
group_right_1 = 1;
5151
break;
5252
default:
5353
PyErr_SetString(PyExc_TypeError, "_opcode.stack_effect requires 1 to 2 arguments");
54-
return NULL;
54+
goto exit;
5555
}
5656
_return_value = _opcode_stack_effect_impl(module, opcode, group_right_1, oparg);
5757
if ((_return_value == -1) && PyErr_Occurred())
@@ -64,7 +64,7 @@ _opcode_stack_effect(PyModuleDef *module, PyObject *args)
6464

6565
static int
6666
_opcode_stack_effect_impl(PyModuleDef *module, int opcode, int group_right_1, int oparg)
67-
/*[clinic end generated code: checksum=47e76ec27523da4ab192713642d32482cd743aa4]*/
67+
/*[clinic end generated code: checksum=58fb4f1b174fc92f783dc945ca712fb752a6c283]*/
6868
{
6969
int effect;
7070
if (HAS_ARG(opcode)) {

Modules/_pickle.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4044,7 +4044,7 @@ to map the new Python 3 names to the old module names used in Python
40444044
[clinic start generated code]*/
40454045

40464046
PyDoc_STRVAR(_pickle_Pickler___init____doc__,
4047-
"__init__(file, protocol=None, fix_imports=True)\n"
4047+
"Pickler(file, protocol=None, fix_imports=True)\n"
40484048
"This takes a binary file for writing a pickle data stream.\n"
40494049
"\n"
40504050
"The optional *protocol* argument tells the pickler to use the given\n"
@@ -4088,7 +4088,7 @@ _pickle_Pickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
40884088

40894089
static int
40904090
_pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, PyObject *protocol, int fix_imports)
4091-
/*[clinic end generated code: checksum=10c8ea05194d08108471163d8202cf5e12975544]*/
4091+
/*[clinic end generated code: checksum=d10dfb463511430b4faad9fca07627041a35b96e]*/
40924092
{
40934093
_Py_IDENTIFIER(persistent_id);
40944094
_Py_IDENTIFIER(dispatch_table);
@@ -6581,7 +6581,7 @@ string instances as bytes objects.
65816581
[clinic start generated code]*/
65826582

65836583
PyDoc_STRVAR(_pickle_Unpickler___init____doc__,
6584-
"__init__(file, *, fix_imports=True, encoding=\'ASCII\', errors=\'strict\')\n"
6584+
"Unpickler(file, *, fix_imports=True, encoding=\'ASCII\', errors=\'strict\')\n"
65856585
"This takes a binary file for reading a pickle data stream.\n"
65866586
"\n"
65876587
"The protocol version of the pickle is detected automatically, so no\n"
@@ -6628,7 +6628,7 @@ _pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
66286628

66296629
static int
66306630
_pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file, int fix_imports, const char *encoding, const char *errors)
6631-
/*[clinic end generated code: checksum=6936e9188104e45b1b15e1c11fe77b3965409471]*/
6631+
/*[clinic end generated code: checksum=eb1a2cfc7b6f97c33980cff3d3b97d184a382f02]*/
66326632
{
66336633
_Py_IDENTIFIER(persistent_load);
66346634

Modules/zlibmodule.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,20 @@ zlib_compress(PyModuleDef *module, PyObject *args)
205205
switch (PyTuple_GET_SIZE(args)) {
206206
case 1:
207207
if (!PyArg_ParseTuple(args, "y*:compress", &bytes))
208-
return NULL;
208+
goto exit;
209209
break;
210210
case 2:
211211
if (!PyArg_ParseTuple(args, "y*i:compress", &bytes, &level))
212-
return NULL;
212+
goto exit;
213213
group_right_1 = 1;
214214
break;
215215
default:
216216
PyErr_SetString(PyExc_TypeError, "zlib.compress requires 1 to 2 arguments");
217-
return NULL;
217+
goto exit;
218218
}
219219
return_value = zlib_compress_impl(module, &bytes, group_right_1, level);
220220

221+
exit:
221222
/* Cleanup for bytes */
222223
if (bytes.obj)
223224
PyBuffer_Release(&bytes);
@@ -227,7 +228,7 @@ zlib_compress(PyModuleDef *module, PyObject *args)
227228

228229
static PyObject *
229230
zlib_compress_impl(PyModuleDef *module, Py_buffer *bytes, int group_right_1, int level)
230-
/*[clinic end generated code: checksum=66c4d16d0b8b9dd423648d9ef00d6a89d3363665]*/
231+
/*[clinic end generated code: checksum=74648f97e6b9d3cc9cd568d47262d462bded7ed0]*/
231232
{
232233
PyObject *ReturnVal = NULL;
233234
Byte *input, *output = NULL;

Tools/clinic/clinic.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ def render_option_group_parsing(self, f, template_dict):
913913
s = """
914914
case {count}:
915915
if (!PyArg_ParseTuple(args, "{format_units}:{name}", {parse_arguments}))
916-
return NULL;
916+
goto exit;
917917
{group_booleans}
918918
break;
919919
"""[1:]
@@ -924,7 +924,7 @@ def render_option_group_parsing(self, f, template_dict):
924924
add(" default:\n")
925925
s = ' PyErr_SetString(PyExc_TypeError, "{} requires {} to {} arguments");\n'
926926
add(s.format(f.full_name, count_min, count_max))
927-
add(' return NULL;\n')
927+
add(' goto exit;\n')
928928
add("}}")
929929
template_dict['option_group_parsing'] = output()
930930

@@ -3401,7 +3401,11 @@ def format_docstring(self):
34013401
## docstring first line
34023402
##
34033403

3404-
add(f.name)
3404+
if f.kind in (METHOD_NEW, METHOD_INIT):
3405+
assert f.cls
3406+
add(f.cls.name)
3407+
else:
3408+
add(f.name)
34053409
add('(')
34063410

34073411
# populate "right_bracket_count" field for every parameter

0 commit comments

Comments
 (0)