summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorRĂ©mi Lapeyre <remi.lapeyre@henki.fr>2019-08-29 14:49:08 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2019-08-29 14:49:08 (GMT)
commit4901fe274bc82b95dc89bcb3de8802a3dfedab32 (patch)
tree2e6e4d0b1cdcb499df7f049ebc9dbbdb9f392bbe /Python
parent59725f3badb3028636c8906ecac4ceb0a37f3982 (diff)
downloadcpython-4901fe274bc82b95dc89bcb3de8802a3dfedab32.zip
cpython-4901fe274bc82b95dc89bcb3de8802a3dfedab32.tar.gz
cpython-4901fe274bc82b95dc89bcb3de8802a3dfedab32.tar.bz2
bpo-37034: Display argument name on errors with keyword arguments with Argument Clinic. (GH-13593)
Diffstat (limited to 'Python')
-rw-r--r--Python/clinic/bltinmodule.c.h6
-rw-r--r--Python/clinic/import.c.h18
-rw-r--r--Python/clinic/marshal.c.h4
-rw-r--r--Python/clinic/sysmodule.c.h6
-rw-r--r--Python/clinic/traceback.c.h4
-rw-r--r--Python/getargs.c22
6 files changed, 27 insertions, 33 deletions
diff --git a/Python/clinic/bltinmodule.c.h b/Python/clinic/bltinmodule.c.h
index abed6cc..49608cc 100644
--- a/Python/clinic/bltinmodule.c.h
+++ b/Python/clinic/bltinmodule.c.h
@@ -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]*/
diff --git a/Python/clinic/import.c.h b/Python/clinic/import.c.h
index 05e3106..743d002 100644
--- a/Python/clinic/import.c.h
+++ b/Python/clinic/import.c.h
@@ -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]*/
diff --git a/Python/clinic/marshal.c.h b/Python/clinic/marshal.c.h
index ab45753..05d4830 100644
--- a/Python/clinic/marshal.c.h
+++ b/Python/clinic/marshal.c.h
@@ -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]*/
diff --git a/Python/clinic/sysmodule.c.h b/Python/clinic/sysmodule.c.h
index 2f3bd14..f9ab28d 100644
--- a/Python/clinic/sysmodule.c.h
+++ b/Python/clinic/sysmodule.c.h
@@ -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]*/
diff --git a/Python/clinic/traceback.c.h b/Python/clinic/traceback.c.h
index 2815f65..04daf2a 100644
--- a/Python/clinic/traceback.c.h
+++ b/Python/clinic/traceback.c.h
@@ -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]*/
diff --git a/Python/getargs.c b/Python/getargs.c
index fe6474c..02a0366 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -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 *