mirror of
https://github.com/python/cpython.git
synced 2025-07-19 09:15:34 +00:00
bpo-37034: Display argument name on errors with keyword arguments with Argument Clinic. (GH-13593)
This commit is contained in:
parent
59725f3bad
commit
4901fe274b
62 changed files with 623 additions and 553 deletions
6
Python/clinic/bltinmodule.c.h
generated
6
Python/clinic/bltinmodule.c.h
generated
|
@ -102,7 +102,7 @@ builtin_format(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
|||
goto skip_optional;
|
||||
}
|
||||
if (!PyUnicode_Check(args[1])) {
|
||||
_PyArg_BadArgument("format", 2, "str", args[1]);
|
||||
_PyArg_BadArgument("format", "argument 2", "str", args[1]);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(args[1]) == -1) {
|
||||
|
@ -200,7 +200,7 @@ builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj
|
|||
goto exit;
|
||||
}
|
||||
if (!PyUnicode_Check(args[2])) {
|
||||
_PyArg_BadArgument("compile", 3, "str", args[2]);
|
||||
_PyArg_BadArgument("compile", "argument 'mode'", "str", args[2]);
|
||||
goto exit;
|
||||
}
|
||||
Py_ssize_t mode_length;
|
||||
|
@ -849,4 +849,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
|||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=e173df340a9e4516 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=1927f3c9abd00c35 input=a9049054013a1b77]*/
|
||||
|
|
18
Python/clinic/import.c.h
generated
18
Python/clinic/import.c.h
generated
|
@ -92,12 +92,12 @@ _imp__fix_co_filename(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
|||
goto exit;
|
||||
}
|
||||
if (!PyObject_TypeCheck(args[0], &PyCode_Type)) {
|
||||
_PyArg_BadArgument("_fix_co_filename", 1, (&PyCode_Type)->tp_name, args[0]);
|
||||
_PyArg_BadArgument("_fix_co_filename", "argument 1", (&PyCode_Type)->tp_name, args[0]);
|
||||
goto exit;
|
||||
}
|
||||
code = (PyCodeObject *)args[0];
|
||||
if (!PyUnicode_Check(args[1])) {
|
||||
_PyArg_BadArgument("_fix_co_filename", 2, "str", args[1]);
|
||||
_PyArg_BadArgument("_fix_co_filename", "argument 2", "str", args[1]);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(args[1]) == -1) {
|
||||
|
@ -156,7 +156,7 @@ _imp_init_frozen(PyObject *module, PyObject *arg)
|
|||
PyObject *name;
|
||||
|
||||
if (!PyUnicode_Check(arg)) {
|
||||
_PyArg_BadArgument("init_frozen", 0, "str", arg);
|
||||
_PyArg_BadArgument("init_frozen", "argument", "str", arg);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(arg) == -1) {
|
||||
|
@ -188,7 +188,7 @@ _imp_get_frozen_object(PyObject *module, PyObject *arg)
|
|||
PyObject *name;
|
||||
|
||||
if (!PyUnicode_Check(arg)) {
|
||||
_PyArg_BadArgument("get_frozen_object", 0, "str", arg);
|
||||
_PyArg_BadArgument("get_frozen_object", "argument", "str", arg);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(arg) == -1) {
|
||||
|
@ -220,7 +220,7 @@ _imp_is_frozen_package(PyObject *module, PyObject *arg)
|
|||
PyObject *name;
|
||||
|
||||
if (!PyUnicode_Check(arg)) {
|
||||
_PyArg_BadArgument("is_frozen_package", 0, "str", arg);
|
||||
_PyArg_BadArgument("is_frozen_package", "argument", "str", arg);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(arg) == -1) {
|
||||
|
@ -252,7 +252,7 @@ _imp_is_builtin(PyObject *module, PyObject *arg)
|
|||
PyObject *name;
|
||||
|
||||
if (!PyUnicode_Check(arg)) {
|
||||
_PyArg_BadArgument("is_builtin", 0, "str", arg);
|
||||
_PyArg_BadArgument("is_builtin", "argument", "str", arg);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(arg) == -1) {
|
||||
|
@ -284,7 +284,7 @@ _imp_is_frozen(PyObject *module, PyObject *arg)
|
|||
PyObject *name;
|
||||
|
||||
if (!PyUnicode_Check(arg)) {
|
||||
_PyArg_BadArgument("is_frozen", 0, "str", arg);
|
||||
_PyArg_BadArgument("is_frozen", "argument", "str", arg);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(arg) == -1) {
|
||||
|
@ -433,7 +433,7 @@ _imp_source_hash(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb
|
|||
goto exit;
|
||||
}
|
||||
if (!PyBuffer_IsContiguous(&source, 'C')) {
|
||||
_PyArg_BadArgument("source_hash", 2, "contiguous buffer", args[1]);
|
||||
_PyArg_BadArgument("source_hash", "argument 'source'", "contiguous buffer", args[1]);
|
||||
goto exit;
|
||||
}
|
||||
return_value = _imp_source_hash_impl(module, key, &source);
|
||||
|
@ -454,4 +454,4 @@ exit:
|
|||
#ifndef _IMP_EXEC_DYNAMIC_METHODDEF
|
||||
#define _IMP_EXEC_DYNAMIC_METHODDEF
|
||||
#endif /* !defined(_IMP_EXEC_DYNAMIC_METHODDEF) */
|
||||
/*[clinic end generated code: output=b51244770fdcf4b8 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=ff06f7cf4b73eb76 input=a9049054013a1b77]*/
|
||||
|
|
4
Python/clinic/marshal.c.h
generated
4
Python/clinic/marshal.c.h
generated
|
@ -152,7 +152,7 @@ marshal_loads(PyObject *module, PyObject *arg)
|
|||
goto exit;
|
||||
}
|
||||
if (!PyBuffer_IsContiguous(&bytes, 'C')) {
|
||||
_PyArg_BadArgument("loads", 0, "contiguous buffer", arg);
|
||||
_PyArg_BadArgument("loads", "argument", "contiguous buffer", arg);
|
||||
goto exit;
|
||||
}
|
||||
return_value = marshal_loads_impl(module, &bytes);
|
||||
|
@ -165,4 +165,4 @@ exit:
|
|||
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=ae2bca1aa239e095 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=a859dabe8b0afeb6 input=a9049054013a1b77]*/
|
||||
|
|
6
Python/clinic/sysmodule.c.h
generated
6
Python/clinic/sysmodule.c.h
generated
|
@ -228,7 +228,7 @@ sys_intern(PyObject *module, PyObject *arg)
|
|||
PyObject *s;
|
||||
|
||||
if (!PyUnicode_Check(arg)) {
|
||||
_PyArg_BadArgument("intern", 0, "str", arg);
|
||||
_PyArg_BadArgument("intern", "argument", "str", arg);
|
||||
goto exit;
|
||||
}
|
||||
if (PyUnicode_READY(arg) == -1) {
|
||||
|
@ -875,7 +875,7 @@ sys_call_tracing(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
|||
}
|
||||
func = args[0];
|
||||
if (!PyTuple_Check(args[1])) {
|
||||
_PyArg_BadArgument("call_tracing", 2, "tuple", args[1]);
|
||||
_PyArg_BadArgument("call_tracing", "argument 2", "tuple", args[1]);
|
||||
goto exit;
|
||||
}
|
||||
funcargs = args[1];
|
||||
|
@ -995,4 +995,4 @@ sys_getandroidapilevel(PyObject *module, PyObject *Py_UNUSED(ignored))
|
|||
#ifndef SYS_GETANDROIDAPILEVEL_METHODDEF
|
||||
#define SYS_GETANDROIDAPILEVEL_METHODDEF
|
||||
#endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */
|
||||
/*[clinic end generated code: output=b26faa0abdd700da input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=8b250245a1265eef input=a9049054013a1b77]*/
|
||||
|
|
4
Python/clinic/traceback.c.h
generated
4
Python/clinic/traceback.c.h
generated
|
@ -32,7 +32,7 @@ tb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
}
|
||||
tb_next = fastargs[0];
|
||||
if (!PyObject_TypeCheck(fastargs[1], &PyFrame_Type)) {
|
||||
_PyArg_BadArgument("TracebackType", 2, (&PyFrame_Type)->tp_name, fastargs[1]);
|
||||
_PyArg_BadArgument("TracebackType", "argument 'tb_frame'", (&PyFrame_Type)->tp_name, fastargs[1]);
|
||||
goto exit;
|
||||
}
|
||||
tb_frame = (PyFrameObject *)fastargs[1];
|
||||
|
@ -59,4 +59,4 @@ tb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=7e4c0e252d0973b0 input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=3def6c06248feed8 input=a9049054013a1b77]*/
|
||||
|
|
|
@ -610,24 +610,18 @@ convertitem(PyObject *arg, const char **p_format, va_list *p_va, int flags,
|
|||
|
||||
|
||||
|
||||
/* Format an error message generated by convertsimple(). */
|
||||
/* Format an error message generated by convertsimple().
|
||||
displayname must be UTF-8 encoded.
|
||||
*/
|
||||
|
||||
void
|
||||
_PyArg_BadArgument(const char *fname, int iarg,
|
||||
_PyArg_BadArgument(const char *fname, const char *displayname,
|
||||
const char *expected, PyObject *arg)
|
||||
{
|
||||
if (iarg) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s() argument %d must be %.50s, not %.50s",
|
||||
fname, iarg, expected,
|
||||
arg == Py_None ? "None" : arg->ob_type->tp_name);
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s() argument must be %.50s, not %.50s",
|
||||
fname, expected,
|
||||
arg == Py_None ? "None" : arg->ob_type->tp_name);
|
||||
}
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s() %.200s must be %.50s, not %.50s",
|
||||
fname, displayname, expected,
|
||||
arg == Py_None ? "None" : arg->ob_type->tp_name);
|
||||
}
|
||||
|
||||
static const char *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue