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).
This commit is contained in:
Larry Hastings 2014-01-22 03:05:49 -08:00
parent 071baa63c4
commit 462582651c
6 changed files with 32 additions and 25 deletions

View File

@ -621,36 +621,37 @@ curses_window_addch(PyObject *self, PyObject *args)
switch (PyTuple_GET_SIZE(args)) {
case 1:
if (!PyArg_ParseTuple(args, "O:addch", &ch))
return NULL;
goto exit;
break;
case 2:
if (!PyArg_ParseTuple(args, "Ol:addch", &ch, &attr))
return NULL;
goto exit;
group_right_1 = 1;
break;
case 3:
if (!PyArg_ParseTuple(args, "iiO:addch", &x, &y, &ch))
return NULL;
goto exit;
group_left_1 = 1;
break;
case 4:
if (!PyArg_ParseTuple(args, "iiOl:addch", &x, &y, &ch, &attr))
return NULL;
goto exit;
group_right_1 = 1;
group_left_1 = 1;
break;
default:
PyErr_SetString(PyExc_TypeError, "curses.window.addch requires 1 to 4 arguments");
return NULL;
goto exit;
}
return_value = curses_window_addch_impl(self, group_left_1, x, y, ch, group_right_1, attr);
exit:
return return_value;
}
static PyObject *
curses_window_addch_impl(PyObject *self, int group_left_1, int x, int y, PyObject *ch, int group_right_1, long attr)
/*[clinic end generated code: checksum=b073327add8197b6ba7fb96c87062422c8312954]*/
/*[clinic end generated code: checksum=53d44d79791b30950972b3256bdd464f7426bf82]*/
{
PyCursesWindowObject *cwself = (PyCursesWindowObject *)self;
int coordinates_group = group_left_1;

View File

@ -300,25 +300,26 @@ dbm_dbm_get(PyObject *self, PyObject *args)
switch (PyTuple_GET_SIZE(args)) {
case 1:
if (!PyArg_ParseTuple(args, "s#:get", &key, &key_length))
return NULL;
goto exit;
break;
case 2:
if (!PyArg_ParseTuple(args, "s#O:get", &key, &key_length, &default_value))
return NULL;
goto exit;
group_right_1 = 1;
break;
default:
PyErr_SetString(PyExc_TypeError, "dbm.dbm.get requires 1 to 2 arguments");
return NULL;
goto exit;
}
return_value = dbm_dbm_get_impl((dbmobject *)self, key, key_length, group_right_1, default_value);
exit:
return return_value;
}
static PyObject *
dbm_dbm_get_impl(dbmobject *dp, const char *key, Py_ssize_clean_t key_length, int group_right_1, PyObject *default_value)
/*[clinic end generated code: checksum=2c3209571267017f1b9abbd19e1b521849fd5d4a]*/
/*[clinic end generated code: checksum=ca8bf63ec226e71d3cf390749777f7d5b7361478]*/
{
datum dbm_key, val;

View File

@ -42,16 +42,16 @@ _opcode_stack_effect(PyModuleDef *module, PyObject *args)
switch (PyTuple_GET_SIZE(args)) {
case 1:
if (!PyArg_ParseTuple(args, "i:stack_effect", &opcode))
return NULL;
goto exit;
break;
case 2:
if (!PyArg_ParseTuple(args, "ii:stack_effect", &opcode, &oparg))
return NULL;
goto exit;
group_right_1 = 1;
break;
default:
PyErr_SetString(PyExc_TypeError, "_opcode.stack_effect requires 1 to 2 arguments");
return NULL;
goto exit;
}
_return_value = _opcode_stack_effect_impl(module, opcode, group_right_1, oparg);
if ((_return_value == -1) && PyErr_Occurred())
@ -64,7 +64,7 @@ exit:
static int
_opcode_stack_effect_impl(PyModuleDef *module, int opcode, int group_right_1, int oparg)
/*[clinic end generated code: checksum=47e76ec27523da4ab192713642d32482cd743aa4]*/
/*[clinic end generated code: checksum=58fb4f1b174fc92f783dc945ca712fb752a6c283]*/
{
int effect;
if (HAS_ARG(opcode)) {

View File

@ -4044,7 +4044,7 @@ to map the new Python 3 names to the old module names used in Python
[clinic start generated code]*/
PyDoc_STRVAR(_pickle_Pickler___init____doc__,
"__init__(file, protocol=None, fix_imports=True)\n"
"Pickler(file, protocol=None, fix_imports=True)\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n"
"The optional *protocol* argument tells the pickler to use the given\n"
@ -4088,7 +4088,7 @@ exit:
static int
_pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, PyObject *protocol, int fix_imports)
/*[clinic end generated code: checksum=10c8ea05194d08108471163d8202cf5e12975544]*/
/*[clinic end generated code: checksum=d10dfb463511430b4faad9fca07627041a35b96e]*/
{
_Py_IDENTIFIER(persistent_id);
_Py_IDENTIFIER(dispatch_table);
@ -6581,7 +6581,7 @@ string instances as bytes objects.
[clinic start generated code]*/
PyDoc_STRVAR(_pickle_Unpickler___init____doc__,
"__init__(file, *, fix_imports=True, encoding=\'ASCII\', errors=\'strict\')\n"
"Unpickler(file, *, fix_imports=True, encoding=\'ASCII\', errors=\'strict\')\n"
"This takes a binary file for reading a pickle data stream.\n"
"\n"
"The protocol version of the pickle is detected automatically, so no\n"
@ -6628,7 +6628,7 @@ exit:
static int
_pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file, int fix_imports, const char *encoding, const char *errors)
/*[clinic end generated code: checksum=6936e9188104e45b1b15e1c11fe77b3965409471]*/
/*[clinic end generated code: checksum=eb1a2cfc7b6f97c33980cff3d3b97d184a382f02]*/
{
_Py_IDENTIFIER(persistent_load);

View File

@ -205,19 +205,20 @@ zlib_compress(PyModuleDef *module, PyObject *args)
switch (PyTuple_GET_SIZE(args)) {
case 1:
if (!PyArg_ParseTuple(args, "y*:compress", &bytes))
return NULL;
goto exit;
break;
case 2:
if (!PyArg_ParseTuple(args, "y*i:compress", &bytes, &level))
return NULL;
goto exit;
group_right_1 = 1;
break;
default:
PyErr_SetString(PyExc_TypeError, "zlib.compress requires 1 to 2 arguments");
return NULL;
goto exit;
}
return_value = zlib_compress_impl(module, &bytes, group_right_1, level);
exit:
/* Cleanup for bytes */
if (bytes.obj)
PyBuffer_Release(&bytes);
@ -227,7 +228,7 @@ zlib_compress(PyModuleDef *module, PyObject *args)
static PyObject *
zlib_compress_impl(PyModuleDef *module, Py_buffer *bytes, int group_right_1, int level)
/*[clinic end generated code: checksum=66c4d16d0b8b9dd423648d9ef00d6a89d3363665]*/
/*[clinic end generated code: checksum=74648f97e6b9d3cc9cd568d47262d462bded7ed0]*/
{
PyObject *ReturnVal = NULL;
Byte *input, *output = NULL;

View File

@ -913,7 +913,7 @@ __________________________________________________
s = """
case {count}:
if (!PyArg_ParseTuple(args, "{format_units}:{name}", {parse_arguments}))
return NULL;
goto exit;
{group_booleans}
break;
"""[1:]
@ -924,7 +924,7 @@ __________________________________________________
add(" default:\n")
s = ' PyErr_SetString(PyExc_TypeError, "{} requires {} to {} arguments");\n'
add(s.format(f.full_name, count_min, count_max))
add(' return NULL;\n')
add(' goto exit;\n')
add("}}")
template_dict['option_group_parsing'] = output()
@ -3401,7 +3401,11 @@ class DSLParser:
## docstring first line
##
add(f.name)
if f.kind in (METHOD_NEW, METHOD_INIT):
assert f.cls
add(f.cls.name)
else:
add(f.name)
add('(')
# populate "right_bracket_count" field for every parameter