Skip to content

Commit 96631dc

Browse files
serhiy-storchakaRémi Lapeyre
andauthored
[3.8] bpo-37034: Display argument name on errors with keyword arguments with Argument Clinic. (GH-13593). (GH-15599)
(cherry picked from commit 4901fe2) Co-authored-by: Rémi Lapeyre <remi.lapeyre@henki.fr>
1 parent 9db66a2 commit 96631dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+623
-553
lines changed

Include/modsupport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ PyAPI_FUNC(int) _PyArg_NoPositional(const char *funcname, PyObject *args);
6666
#define _PyArg_NoPositional(funcname, args) \
6767
((args) == NULL || _PyArg_NoPositional((funcname), (args)))
6868

69-
PyAPI_FUNC(void) _PyArg_BadArgument(const char *, int, const char *, PyObject *);
69+
PyAPI_FUNC(void) _PyArg_BadArgument(const char *, const char *, const char *, PyObject *);
7070
PyAPI_FUNC(int) _PyArg_CheckPositional(const char *, Py_ssize_t,
7171
Py_ssize_t, Py_ssize_t);
7272
#define _PyArg_CheckPositional(funcname, nargs, min, max) \

Lib/test/clinic.test

Lines changed: 94 additions & 41 deletions
Large diffs are not rendered by default.

Lib/test/test_pyexpat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def test_illegal(self):
285285
self.fail()
286286
except TypeError as e:
287287
self.assertEqual(str(e),
288-
'ParserCreate() argument 2 must be str or None, not int')
288+
"ParserCreate() argument 'namespace_separator' must be str or None, not int")
289289

290290
try:
291291
expat.ParserCreate(namespace_separator='too long')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Argument Clinic now uses the argument name on errors with keyword-only
2+
argument instead of their position. Patch contributed by Rémi Lapeyre.

Modules/_blake2/clinic/blake2b_impl.c.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ py_blake2b_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
7272
goto exit;
7373
}
7474
if (!PyBuffer_IsContiguous(&key, 'C')) {
75-
_PyArg_BadArgument("blake2b", 3, "contiguous buffer", fastargs[2]);
75+
_PyArg_BadArgument("blake2b", "argument 'key'", "contiguous buffer", fastargs[2]);
7676
goto exit;
7777
}
7878
if (!--noptargs) {
@@ -84,7 +84,7 @@ py_blake2b_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
8484
goto exit;
8585
}
8686
if (!PyBuffer_IsContiguous(&salt, 'C')) {
87-
_PyArg_BadArgument("blake2b", 4, "contiguous buffer", fastargs[3]);
87+
_PyArg_BadArgument("blake2b", "argument 'salt'", "contiguous buffer", fastargs[3]);
8888
goto exit;
8989
}
9090
if (!--noptargs) {
@@ -96,7 +96,7 @@ py_blake2b_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
9696
goto exit;
9797
}
9898
if (!PyBuffer_IsContiguous(&person, 'C')) {
99-
_PyArg_BadArgument("blake2b", 5, "contiguous buffer", fastargs[4]);
99+
_PyArg_BadArgument("blake2b", "argument 'person'", "contiguous buffer", fastargs[4]);
100100
goto exit;
101101
}
102102
if (!--noptargs) {
@@ -261,4 +261,4 @@ _blake2_blake2b_hexdigest(BLAKE2bObject *self, PyObject *Py_UNUSED(ignored))
261261
{
262262
return _blake2_blake2b_hexdigest_impl(self);
263263
}
264-
/*[clinic end generated code: output=a91d182ce1109f34 input=a9049054013a1b77]*/
264+
/*[clinic end generated code: output=cbb625d7f60c288c input=a9049054013a1b77]*/

Modules/_blake2/clinic/blake2s_impl.c.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ py_blake2s_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
7272
goto exit;
7373
}
7474
if (!PyBuffer_IsContiguous(&key, 'C')) {
75-
_PyArg_BadArgument("blake2s", 3, "contiguous buffer", fastargs[2]);
75+
_PyArg_BadArgument("blake2s", "argument 'key'", "contiguous buffer", fastargs[2]);
7676
goto exit;
7777
}
7878
if (!--noptargs) {
@@ -84,7 +84,7 @@ py_blake2s_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
8484
goto exit;
8585
}
8686
if (!PyBuffer_IsContiguous(&salt, 'C')) {
87-
_PyArg_BadArgument("blake2s", 4, "contiguous buffer", fastargs[3]);
87+
_PyArg_BadArgument("blake2s", "argument 'salt'", "contiguous buffer", fastargs[3]);
8888
goto exit;
8989
}
9090
if (!--noptargs) {
@@ -96,7 +96,7 @@ py_blake2s_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
9696
goto exit;
9797
}
9898
if (!PyBuffer_IsContiguous(&person, 'C')) {
99-
_PyArg_BadArgument("blake2s", 5, "contiguous buffer", fastargs[4]);
99+
_PyArg_BadArgument("blake2s", "argument 'person'", "contiguous buffer", fastargs[4]);
100100
goto exit;
101101
}
102102
if (!--noptargs) {
@@ -261,4 +261,4 @@ _blake2_blake2s_hexdigest(BLAKE2sObject *self, PyObject *Py_UNUSED(ignored))
261261
{
262262
return _blake2_blake2s_hexdigest_impl(self);
263263
}
264-
/*[clinic end generated code: output=ae8e9b7301d092b4 input=a9049054013a1b77]*/
264+
/*[clinic end generated code: output=39af5a74c8805b36 input=a9049054013a1b77]*/

Modules/_io/clinic/_iomodule.c.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
161161
}
162162
if (args[1]) {
163163
if (!PyUnicode_Check(args[1])) {
164-
_PyArg_BadArgument("open", 2, "str", args[1]);
164+
_PyArg_BadArgument("open", "argument 'mode'", "str", args[1]);
165165
goto exit;
166166
}
167167
Py_ssize_t mode_length;
@@ -207,7 +207,7 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
207207
}
208208
}
209209
else {
210-
_PyArg_BadArgument("open", 4, "str or None", args[3]);
210+
_PyArg_BadArgument("open", "argument 'encoding'", "str or None", args[3]);
211211
goto exit;
212212
}
213213
if (!--noptargs) {
@@ -230,7 +230,7 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
230230
}
231231
}
232232
else {
233-
_PyArg_BadArgument("open", 5, "str or None", args[4]);
233+
_PyArg_BadArgument("open", "argument 'errors'", "str or None", args[4]);
234234
goto exit;
235235
}
236236
if (!--noptargs) {
@@ -253,7 +253,7 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
253253
}
254254
}
255255
else {
256-
_PyArg_BadArgument("open", 6, "str or None", args[5]);
256+
_PyArg_BadArgument("open", "argument 'newline'", "str or None", args[5]);
257257
goto exit;
258258
}
259259
if (!--noptargs) {
@@ -311,7 +311,7 @@ _io_open_code(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
311311
goto exit;
312312
}
313313
if (!PyUnicode_Check(args[0])) {
314-
_PyArg_BadArgument("open_code", 1, "str", args[0]);
314+
_PyArg_BadArgument("open_code", "argument 'path'", "str", args[0]);
315315
goto exit;
316316
}
317317
if (PyUnicode_READY(args[0]) == -1) {
@@ -323,4 +323,4 @@ _io_open_code(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
323323
exit:
324324
return return_value;
325325
}
326-
/*[clinic end generated code: output=d479285078750d68 input=a9049054013a1b77]*/
326+
/*[clinic end generated code: output=3df6bc6d91697545 input=a9049054013a1b77]*/

Modules/_io/clinic/bufferedio.c.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ _io__BufferedIOBase_readinto(PyObject *self, PyObject *arg)
2121

2222
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
2323
PyErr_Clear();
24-
_PyArg_BadArgument("readinto", 0, "read-write bytes-like object", arg);
24+
_PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
2525
goto exit;
2626
}
2727
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
28-
_PyArg_BadArgument("readinto", 0, "contiguous buffer", arg);
28+
_PyArg_BadArgument("readinto", "argument", "contiguous buffer", arg);
2929
goto exit;
3030
}
3131
return_value = _io__BufferedIOBase_readinto_impl(self, &buffer);
@@ -58,11 +58,11 @@ _io__BufferedIOBase_readinto1(PyObject *self, PyObject *arg)
5858

5959
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
6060
PyErr_Clear();
61-
_PyArg_BadArgument("readinto1", 0, "read-write bytes-like object", arg);
61+
_PyArg_BadArgument("readinto1", "argument", "read-write bytes-like object", arg);
6262
goto exit;
6363
}
6464
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
65-
_PyArg_BadArgument("readinto1", 0, "contiguous buffer", arg);
65+
_PyArg_BadArgument("readinto1", "argument", "contiguous buffer", arg);
6666
goto exit;
6767
}
6868
return_value = _io__BufferedIOBase_readinto1_impl(self, &buffer);
@@ -243,11 +243,11 @@ _io__Buffered_readinto(buffered *self, PyObject *arg)
243243

244244
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
245245
PyErr_Clear();
246-
_PyArg_BadArgument("readinto", 0, "read-write bytes-like object", arg);
246+
_PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
247247
goto exit;
248248
}
249249
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
250-
_PyArg_BadArgument("readinto", 0, "contiguous buffer", arg);
250+
_PyArg_BadArgument("readinto", "argument", "contiguous buffer", arg);
251251
goto exit;
252252
}
253253
return_value = _io__Buffered_readinto_impl(self, &buffer);
@@ -280,11 +280,11 @@ _io__Buffered_readinto1(buffered *self, PyObject *arg)
280280

281281
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
282282
PyErr_Clear();
283-
_PyArg_BadArgument("readinto1", 0, "read-write bytes-like object", arg);
283+
_PyArg_BadArgument("readinto1", "argument", "read-write bytes-like object", arg);
284284
goto exit;
285285
}
286286
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
287-
_PyArg_BadArgument("readinto1", 0, "contiguous buffer", arg);
287+
_PyArg_BadArgument("readinto1", "argument", "contiguous buffer", arg);
288288
goto exit;
289289
}
290290
return_value = _io__Buffered_readinto1_impl(self, &buffer);
@@ -538,7 +538,7 @@ _io_BufferedWriter_write(buffered *self, PyObject *arg)
538538
goto exit;
539539
}
540540
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
541-
_PyArg_BadArgument("write", 0, "contiguous buffer", arg);
541+
_PyArg_BadArgument("write", "argument", "contiguous buffer", arg);
542542
goto exit;
543543
}
544544
return_value = _io_BufferedWriter_write_impl(self, &buffer);
@@ -672,4 +672,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs)
672672
exit:
673673
return return_value;
674674
}
675-
/*[clinic end generated code: output=b22b4aedd53c340a input=a9049054013a1b77]*/
675+
/*[clinic end generated code: output=7246104f6c7d3167 input=a9049054013a1b77]*/

Modules/_io/clinic/bytesio.c.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,11 @@ _io_BytesIO_readinto(bytesio *self, PyObject *arg)
319319

320320
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
321321
PyErr_Clear();
322-
_PyArg_BadArgument("readinto", 0, "read-write bytes-like object", arg);
322+
_PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
323323
goto exit;
324324
}
325325
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
326-
_PyArg_BadArgument("readinto", 0, "contiguous buffer", arg);
326+
_PyArg_BadArgument("readinto", "argument", "contiguous buffer", arg);
327327
goto exit;
328328
}
329329
return_value = _io_BytesIO_readinto_impl(self, &buffer);
@@ -515,4 +515,4 @@ _io_BytesIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
515515
exit:
516516
return return_value;
517517
}
518-
/*[clinic end generated code: output=22e8fb54874b6ee5 input=a9049054013a1b77]*/
518+
/*[clinic end generated code: output=4ec2506def9c8eb9 input=a9049054013a1b77]*/

Modules/_io/clinic/fileio.c.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ _io_FileIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
7070
}
7171
if (fastargs[1]) {
7272
if (!PyUnicode_Check(fastargs[1])) {
73-
_PyArg_BadArgument("FileIO", 2, "str", fastargs[1]);
73+
_PyArg_BadArgument("FileIO", "argument 'mode'", "str", fastargs[1]);
7474
goto exit;
7575
}
7676
Py_ssize_t mode_length;
@@ -200,11 +200,11 @@ _io_FileIO_readinto(fileio *self, PyObject *arg)
200200

201201
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
202202
PyErr_Clear();
203-
_PyArg_BadArgument("readinto", 0, "read-write bytes-like object", arg);
203+
_PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
204204
goto exit;
205205
}
206206
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
207-
_PyArg_BadArgument("readinto", 0, "contiguous buffer", arg);
207+
_PyArg_BadArgument("readinto", "argument", "contiguous buffer", arg);
208208
goto exit;
209209
}
210210
return_value = _io_FileIO_readinto_impl(self, &buffer);
@@ -303,7 +303,7 @@ _io_FileIO_write(fileio *self, PyObject *arg)
303303
goto exit;
304304
}
305305
if (!PyBuffer_IsContiguous(&b, 'C')) {
306-
_PyArg_BadArgument("write", 0, "contiguous buffer", arg);
306+
_PyArg_BadArgument("write", "argument", "contiguous buffer", arg);
307307
goto exit;
308308
}
309309
return_value = _io_FileIO_write_impl(self, &b);
@@ -447,4 +447,4 @@ _io_FileIO_isatty(fileio *self, PyObject *Py_UNUSED(ignored))
447447
#ifndef _IO_FILEIO_TRUNCATE_METHODDEF
448448
#define _IO_FILEIO_TRUNCATE_METHODDEF
449449
#endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */
450-
/*[clinic end generated code: output=7ee4f3ae584fc6d2 input=a9049054013a1b77]*/
450+
/*[clinic end generated code: output=a7e9cca3613660fb input=a9049054013a1b77]*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy