Skip to content

[3.8] bpo-37034: Display argument name on errors with keyword arguments with Argument Clinic. (GH-13593). #15599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Include/modsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ PyAPI_FUNC(int) _PyArg_NoPositional(const char *funcname, PyObject *args);
#define _PyArg_NoPositional(funcname, args) \
((args) == NULL || _PyArg_NoPositional((funcname), (args)))

PyAPI_FUNC(void) _PyArg_BadArgument(const char *, int, const char *, PyObject *);
PyAPI_FUNC(void) _PyArg_BadArgument(const char *, const char *, const char *, PyObject *);
PyAPI_FUNC(int) _PyArg_CheckPositional(const char *, Py_ssize_t,
Py_ssize_t, Py_ssize_t);
#define _PyArg_CheckPositional(funcname, nargs, min, max) \
Expand Down
135 changes: 94 additions & 41 deletions Lib/test/clinic.test

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Lib/test/test_pyexpat.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def test_illegal(self):
self.fail()
except TypeError as e:
self.assertEqual(str(e),
'ParserCreate() argument 2 must be str or None, not int')
"ParserCreate() argument 'namespace_separator' must be str or None, not int")

try:
expat.ParserCreate(namespace_separator='too long')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Argument Clinic now uses the argument name on errors with keyword-only
argument instead of their position. Patch contributed by Rémi Lapeyre.
8 changes: 4 additions & 4 deletions Modules/_blake2/clinic/blake2b_impl.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ py_blake2b_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
goto exit;
}
if (!PyBuffer_IsContiguous(&key, 'C')) {
_PyArg_BadArgument("blake2b", 3, "contiguous buffer", fastargs[2]);
_PyArg_BadArgument("blake2b", "argument 'key'", "contiguous buffer", fastargs[2]);
goto exit;
}
if (!--noptargs) {
Expand All @@ -84,7 +84,7 @@ py_blake2b_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
goto exit;
}
if (!PyBuffer_IsContiguous(&salt, 'C')) {
_PyArg_BadArgument("blake2b", 4, "contiguous buffer", fastargs[3]);
_PyArg_BadArgument("blake2b", "argument 'salt'", "contiguous buffer", fastargs[3]);
goto exit;
}
if (!--noptargs) {
Expand All @@ -96,7 +96,7 @@ py_blake2b_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
goto exit;
}
if (!PyBuffer_IsContiguous(&person, 'C')) {
_PyArg_BadArgument("blake2b", 5, "contiguous buffer", fastargs[4]);
_PyArg_BadArgument("blake2b", "argument 'person'", "contiguous buffer", fastargs[4]);
goto exit;
}
if (!--noptargs) {
Expand Down Expand Up @@ -261,4 +261,4 @@ _blake2_blake2b_hexdigest(BLAKE2bObject *self, PyObject *Py_UNUSED(ignored))
{
return _blake2_blake2b_hexdigest_impl(self);
}
/*[clinic end generated code: output=a91d182ce1109f34 input=a9049054013a1b77]*/
/*[clinic end generated code: output=cbb625d7f60c288c input=a9049054013a1b77]*/
8 changes: 4 additions & 4 deletions Modules/_blake2/clinic/blake2s_impl.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ py_blake2s_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
goto exit;
}
if (!PyBuffer_IsContiguous(&key, 'C')) {
_PyArg_BadArgument("blake2s", 3, "contiguous buffer", fastargs[2]);
_PyArg_BadArgument("blake2s", "argument 'key'", "contiguous buffer", fastargs[2]);
goto exit;
}
if (!--noptargs) {
Expand All @@ -84,7 +84,7 @@ py_blake2s_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
goto exit;
}
if (!PyBuffer_IsContiguous(&salt, 'C')) {
_PyArg_BadArgument("blake2s", 4, "contiguous buffer", fastargs[3]);
_PyArg_BadArgument("blake2s", "argument 'salt'", "contiguous buffer", fastargs[3]);
goto exit;
}
if (!--noptargs) {
Expand All @@ -96,7 +96,7 @@ py_blake2s_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
goto exit;
}
if (!PyBuffer_IsContiguous(&person, 'C')) {
_PyArg_BadArgument("blake2s", 5, "contiguous buffer", fastargs[4]);
_PyArg_BadArgument("blake2s", "argument 'person'", "contiguous buffer", fastargs[4]);
goto exit;
}
if (!--noptargs) {
Expand Down Expand Up @@ -261,4 +261,4 @@ _blake2_blake2s_hexdigest(BLAKE2sObject *self, PyObject *Py_UNUSED(ignored))
{
return _blake2_blake2s_hexdigest_impl(self);
}
/*[clinic end generated code: output=ae8e9b7301d092b4 input=a9049054013a1b77]*/
/*[clinic end generated code: output=39af5a74c8805b36 input=a9049054013a1b77]*/
12 changes: 6 additions & 6 deletions Modules/_io/clinic/_iomodule.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
}
if (args[1]) {
if (!PyUnicode_Check(args[1])) {
_PyArg_BadArgument("open", 2, "str", args[1]);
_PyArg_BadArgument("open", "argument 'mode'", "str", args[1]);
goto exit;
}
Py_ssize_t mode_length;
Expand Down Expand Up @@ -207,7 +207,7 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
}
}
else {
_PyArg_BadArgument("open", 4, "str or None", args[3]);
_PyArg_BadArgument("open", "argument 'encoding'", "str or None", args[3]);
goto exit;
}
if (!--noptargs) {
Expand All @@ -230,7 +230,7 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
}
}
else {
_PyArg_BadArgument("open", 5, "str or None", args[4]);
_PyArg_BadArgument("open", "argument 'errors'", "str or None", args[4]);
goto exit;
}
if (!--noptargs) {
Expand All @@ -253,7 +253,7 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
}
}
else {
_PyArg_BadArgument("open", 6, "str or None", args[5]);
_PyArg_BadArgument("open", "argument 'newline'", "str or None", args[5]);
goto exit;
}
if (!--noptargs) {
Expand Down Expand Up @@ -311,7 +311,7 @@ _io_open_code(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
goto exit;
}
if (!PyUnicode_Check(args[0])) {
_PyArg_BadArgument("open_code", 1, "str", args[0]);
_PyArg_BadArgument("open_code", "argument 'path'", "str", args[0]);
goto exit;
}
if (PyUnicode_READY(args[0]) == -1) {
Expand All @@ -323,4 +323,4 @@ _io_open_code(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
exit:
return return_value;
}
/*[clinic end generated code: output=d479285078750d68 input=a9049054013a1b77]*/
/*[clinic end generated code: output=3df6bc6d91697545 input=a9049054013a1b77]*/
20 changes: 10 additions & 10 deletions Modules/_io/clinic/bufferedio.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ _io__BufferedIOBase_readinto(PyObject *self, PyObject *arg)

if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
PyErr_Clear();
_PyArg_BadArgument("readinto", 0, "read-write bytes-like object", arg);
_PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
_PyArg_BadArgument("readinto", 0, "contiguous buffer", arg);
_PyArg_BadArgument("readinto", "argument", "contiguous buffer", arg);
goto exit;
}
return_value = _io__BufferedIOBase_readinto_impl(self, &buffer);
Expand Down Expand Up @@ -58,11 +58,11 @@ _io__BufferedIOBase_readinto1(PyObject *self, PyObject *arg)

if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
PyErr_Clear();
_PyArg_BadArgument("readinto1", 0, "read-write bytes-like object", arg);
_PyArg_BadArgument("readinto1", "argument", "read-write bytes-like object", arg);
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
_PyArg_BadArgument("readinto1", 0, "contiguous buffer", arg);
_PyArg_BadArgument("readinto1", "argument", "contiguous buffer", arg);
goto exit;
}
return_value = _io__BufferedIOBase_readinto1_impl(self, &buffer);
Expand Down Expand Up @@ -243,11 +243,11 @@ _io__Buffered_readinto(buffered *self, PyObject *arg)

if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
PyErr_Clear();
_PyArg_BadArgument("readinto", 0, "read-write bytes-like object", arg);
_PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
_PyArg_BadArgument("readinto", 0, "contiguous buffer", arg);
_PyArg_BadArgument("readinto", "argument", "contiguous buffer", arg);
goto exit;
}
return_value = _io__Buffered_readinto_impl(self, &buffer);
Expand Down Expand Up @@ -280,11 +280,11 @@ _io__Buffered_readinto1(buffered *self, PyObject *arg)

if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
PyErr_Clear();
_PyArg_BadArgument("readinto1", 0, "read-write bytes-like object", arg);
_PyArg_BadArgument("readinto1", "argument", "read-write bytes-like object", arg);
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
_PyArg_BadArgument("readinto1", 0, "contiguous buffer", arg);
_PyArg_BadArgument("readinto1", "argument", "contiguous buffer", arg);
goto exit;
}
return_value = _io__Buffered_readinto1_impl(self, &buffer);
Expand Down Expand Up @@ -538,7 +538,7 @@ _io_BufferedWriter_write(buffered *self, PyObject *arg)
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
_PyArg_BadArgument("write", 0, "contiguous buffer", arg);
_PyArg_BadArgument("write", "argument", "contiguous buffer", arg);
goto exit;
}
return_value = _io_BufferedWriter_write_impl(self, &buffer);
Expand Down Expand Up @@ -672,4 +672,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
/*[clinic end generated code: output=b22b4aedd53c340a input=a9049054013a1b77]*/
/*[clinic end generated code: output=7246104f6c7d3167 input=a9049054013a1b77]*/
6 changes: 3 additions & 3 deletions Modules/_io/clinic/bytesio.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,11 @@ _io_BytesIO_readinto(bytesio *self, PyObject *arg)

if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
PyErr_Clear();
_PyArg_BadArgument("readinto", 0, "read-write bytes-like object", arg);
_PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
_PyArg_BadArgument("readinto", 0, "contiguous buffer", arg);
_PyArg_BadArgument("readinto", "argument", "contiguous buffer", arg);
goto exit;
}
return_value = _io_BytesIO_readinto_impl(self, &buffer);
Expand Down Expand Up @@ -515,4 +515,4 @@ _io_BytesIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
/*[clinic end generated code: output=22e8fb54874b6ee5 input=a9049054013a1b77]*/
/*[clinic end generated code: output=4ec2506def9c8eb9 input=a9049054013a1b77]*/
10 changes: 5 additions & 5 deletions Modules/_io/clinic/fileio.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ _io_FileIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
}
if (fastargs[1]) {
if (!PyUnicode_Check(fastargs[1])) {
_PyArg_BadArgument("FileIO", 2, "str", fastargs[1]);
_PyArg_BadArgument("FileIO", "argument 'mode'", "str", fastargs[1]);
goto exit;
}
Py_ssize_t mode_length;
Expand Down Expand Up @@ -200,11 +200,11 @@ _io_FileIO_readinto(fileio *self, PyObject *arg)

if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
PyErr_Clear();
_PyArg_BadArgument("readinto", 0, "read-write bytes-like object", arg);
_PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
_PyArg_BadArgument("readinto", 0, "contiguous buffer", arg);
_PyArg_BadArgument("readinto", "argument", "contiguous buffer", arg);
goto exit;
}
return_value = _io_FileIO_readinto_impl(self, &buffer);
Expand Down Expand Up @@ -303,7 +303,7 @@ _io_FileIO_write(fileio *self, PyObject *arg)
goto exit;
}
if (!PyBuffer_IsContiguous(&b, 'C')) {
_PyArg_BadArgument("write", 0, "contiguous buffer", arg);
_PyArg_BadArgument("write", "argument", "contiguous buffer", arg);
goto exit;
}
return_value = _io_FileIO_write_impl(self, &b);
Expand Down Expand Up @@ -447,4 +447,4 @@ _io_FileIO_isatty(fileio *self, PyObject *Py_UNUSED(ignored))
#ifndef _IO_FILEIO_TRUNCATE_METHODDEF
#define _IO_FILEIO_TRUNCATE_METHODDEF
#endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */
/*[clinic end generated code: output=7ee4f3ae584fc6d2 input=a9049054013a1b77]*/
/*[clinic end generated code: output=a7e9cca3613660fb input=a9049054013a1b77]*/
8 changes: 4 additions & 4 deletions Modules/_io/clinic/textio.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ _io_TextIOWrapper___init__(PyObject *self, PyObject *args, PyObject *kwargs)
}
}
else {
_PyArg_BadArgument("TextIOWrapper", 2, "str or None", fastargs[1]);
_PyArg_BadArgument("TextIOWrapper", "argument 'encoding'", "str or None", fastargs[1]);
goto exit;
}
if (!--noptargs) {
Expand Down Expand Up @@ -258,7 +258,7 @@ _io_TextIOWrapper___init__(PyObject *self, PyObject *args, PyObject *kwargs)
}
}
else {
_PyArg_BadArgument("TextIOWrapper", 4, "str or None", fastargs[3]);
_PyArg_BadArgument("TextIOWrapper", "argument 'newline'", "str or None", fastargs[3]);
goto exit;
}
if (!--noptargs) {
Expand Down Expand Up @@ -401,7 +401,7 @@ _io_TextIOWrapper_write(textio *self, PyObject *arg)
PyObject *text;

if (!PyUnicode_Check(arg)) {
_PyArg_BadArgument("write", 0, "str", arg);
_PyArg_BadArgument("write", "argument", "str", arg);
goto exit;
}
if (PyUnicode_READY(arg) == -1) {
Expand Down Expand Up @@ -701,4 +701,4 @@ _io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored))
{
return _io_TextIOWrapper_close_impl(self);
}
/*[clinic end generated code: output=b651e056e3000f88 input=a9049054013a1b77]*/
/*[clinic end generated code: output=b1bae4f4cdf6019e input=a9049054013a1b77]*/
10 changes: 5 additions & 5 deletions Modules/_io/clinic/winconsoleio.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ _io__WindowsConsoleIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
}
if (fastargs[1]) {
if (!PyUnicode_Check(fastargs[1])) {
_PyArg_BadArgument("_WindowsConsoleIO", 2, "str", fastargs[1]);
_PyArg_BadArgument("_WindowsConsoleIO", "argument 'mode'", "str", fastargs[1]);
goto exit;
}
Py_ssize_t mode_length;
Expand Down Expand Up @@ -200,11 +200,11 @@ _io__WindowsConsoleIO_readinto(winconsoleio *self, PyObject *arg)

if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
PyErr_Clear();
_PyArg_BadArgument("readinto", 0, "read-write bytes-like object", arg);
_PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
goto exit;
}
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
_PyArg_BadArgument("readinto", 0, "contiguous buffer", arg);
_PyArg_BadArgument("readinto", "argument", "contiguous buffer", arg);
goto exit;
}
return_value = _io__WindowsConsoleIO_readinto_impl(self, &buffer);
Expand Down Expand Up @@ -313,7 +313,7 @@ _io__WindowsConsoleIO_write(winconsoleio *self, PyObject *arg)
goto exit;
}
if (!PyBuffer_IsContiguous(&b, 'C')) {
_PyArg_BadArgument("write", 0, "contiguous buffer", arg);
_PyArg_BadArgument("write", "argument", "contiguous buffer", arg);
goto exit;
}
return_value = _io__WindowsConsoleIO_write_impl(self, &b);
Expand Down Expand Up @@ -386,4 +386,4 @@ _io__WindowsConsoleIO_isatty(winconsoleio *self, PyObject *Py_UNUSED(ignored))
#ifndef _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
#define _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
#endif /* !defined(_IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF) */
/*[clinic end generated code: output=57bf2c09a42bd330 input=a9049054013a1b77]*/
/*[clinic end generated code: output=f5b8860a658a001a input=a9049054013a1b77]*/
6 changes: 3 additions & 3 deletions Modules/_multiprocessing/clinic/posixshmem.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ _posixshmem_shm_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs,
goto exit;
}
if (!PyUnicode_Check(args[0])) {
_PyArg_BadArgument("shm_open", 1, "str", args[0]);
_PyArg_BadArgument("shm_open", "argument 'path'", "str", args[0]);
goto exit;
}
if (PyUnicode_READY(args[0]) == -1) {
Expand Down Expand Up @@ -108,7 +108,7 @@ _posixshmem_shm_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs
goto exit;
}
if (!PyUnicode_Check(args[0])) {
_PyArg_BadArgument("shm_unlink", 1, "str", args[0]);
_PyArg_BadArgument("shm_unlink", "argument 'path'", "str", args[0]);
goto exit;
}
if (PyUnicode_READY(args[0]) == -1) {
Expand All @@ -130,4 +130,4 @@ _posixshmem_shm_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs
#ifndef _POSIXSHMEM_SHM_UNLINK_METHODDEF
#define _POSIXSHMEM_SHM_UNLINK_METHODDEF
#endif /* !defined(_POSIXSHMEM_SHM_UNLINK_METHODDEF) */
/*[clinic end generated code: output=be42e23c18677c0f input=a9049054013a1b77]*/
/*[clinic end generated code: output=9132861c61d8c2d8 input=a9049054013a1b77]*/
Loading