bpo-30600: Fix error messages (condition order in Argument Clinic) (#… · pythoncapi/cpython@7445381 · GitHub
Skip to content

Commit 7445381

Browse files
SylvainDeserhiy-storchaka
authored andcommitted
bpo-30600: Fix error messages (condition order in Argument Clinic) (python#2051)
The function '_PyArg_ParseStack()' and '_PyArg_UnpackStack' were failing (with error "XXX() takes Y argument (Z given)") before the function '_PyArg_NoStackKeywords()' was called. Thus, the latter did not raise its more meaningful error : "XXX() takes no keyword arguments".
1 parent e5f6e86 commit 7445381

51 files changed

Lines changed: 1116 additions & 1104 deletions

Some content is hidden

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

Lib/test/test_call.py

Lines changed: 12 additions & 0 deletions

Modules/_io/clinic/bufferedio.c.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ _io__Buffered_peek(buffered *self, PyObject **args, Py_ssize_t nargs, PyObject *
102102
PyObject *return_value = NULL;
103103
Py_ssize_t size = 0;
104104

105-
if (!_PyArg_ParseStack(args, nargs, "|n:peek",
106-
&size)) {
105+
if (!_PyArg_NoStackKeywords("peek", kwnames)) {
107106
goto exit;
108107
}
109108

110-
if (!_PyArg_NoStackKeywords("peek", kwnames)) {
109+
if (!_PyArg_ParseStack(args, nargs, "|n:peek",
110+
&size)) {
111111
goto exit;
112112
}
113113
return_value = _io__Buffered_peek_impl(self, size);
@@ -133,12 +133,12 @@ _io__Buffered_read(buffered *self, PyObject **args, Py_ssize_t nargs, PyObject *
133133
PyObject *return_value = NULL;
134134
Py_ssize_t n = -1;
135135

136-
if (!_PyArg_ParseStack(args, nargs, "|O&:read",
137-
_Py_convert_optional_to_ssize_t, &n)) {
136+
if (!_PyArg_NoStackKeywords("read", kwnames)) {
138137
goto exit;
139138
}
140139

141-
if (!_PyArg_NoStackKeywords("read", kwnames)) {
140+
if (!_PyArg_ParseStack(args, nargs, "|O&:read",
141+
_Py_convert_optional_to_ssize_t, &n)) {
142142
goto exit;
143143
}
144144
return_value = _io__Buffered_read_impl(self, n);
@@ -164,12 +164,12 @@ _io__Buffered_read1(buffered *self, PyObject **args, Py_ssize_t nargs, PyObject
164164
PyObject *return_value = NULL;
165165
Py_ssize_t n = -1;
166166

167-
if (!_PyArg_ParseStack(args, nargs, "|n:read1",
168-
&n)) {
167+
if (!_PyArg_NoStackKeywords("read1", kwnames)) {
169168
goto exit;
170169
}
171170

172-
if (!_PyArg_NoStackKeywords("read1", kwnames)) {
171+
if (!_PyArg_ParseStack(args, nargs, "|n:read1",
172+
&n)) {
173173
goto exit;
174174
}
175175
return_value = _io__Buffered_read1_impl(self, n);
@@ -257,12 +257,12 @@ _io__Buffered_readline(buffered *self, PyObject **args, Py_ssize_t nargs, PyObje
257257
PyObject *return_value = NULL;
258258
Py_ssize_t size = -1;
259259

260-
if (!_PyArg_ParseStack(args, nargs, "|O&:readline",
261-
_Py_convert_optional_to_ssize_t, &size)) {
260+
if (!_PyArg_NoStackKeywords("readline", kwnames)) {
262261
goto exit;
263262
}
264263

265-
if (!_PyArg_NoStackKeywords("readline", kwnames)) {
264+
if (!_PyArg_ParseStack(args, nargs, "|O&:readline",
265+
_Py_convert_optional_to_ssize_t, &size)) {
266266
goto exit;
267267
}
268268
return_value = _io__Buffered_readline_impl(self, size);
@@ -289,12 +289,12 @@ _io__Buffered_seek(buffered *self, PyObject **args, Py_ssize_t nargs, PyObject *
289289
PyObject *targetobj;
290290
int whence = 0;
291291

292-
if (!_PyArg_ParseStack(args, nargs, "O|i:seek",
293-
&targetobj, &whence)) {
292+
if (!_PyArg_NoStackKeywords("seek", kwnames)) {
294293
goto exit;
295294
}
296295

297-
if (!_PyArg_NoStackKeywords("seek", kwnames)) {
296+
if (!_PyArg_ParseStack(args, nargs, "O|i:seek",
297+
&targetobj, &whence)) {
298298
goto exit;
299299
}
300300
return_value = _io__Buffered_seek_impl(self, targetobj, whence);
@@ -320,13 +320,13 @@ _io__Buffered_truncate(buffered *self, PyObject **args, Py_ssize_t nargs, PyObje
320320
PyObject *return_value = NULL;
321321
PyObject *pos = Py_None;
322322

323-
if (!_PyArg_UnpackStack(args, nargs, "truncate",
324-
0, 1,
325-
&pos)) {
323+
if (!_PyArg_NoStackKeywords("truncate", kwnames)) {
326324
goto exit;
327325
}
328326

329-
if (!_PyArg_NoStackKeywords("truncate", kwnames)) {
327+
if (!_PyArg_UnpackStack(args, nargs, "truncate",
328+
0, 1,
329+
&pos)) {
330330
goto exit;
331331
}
332332
return_value = _io__Buffered_truncate_impl(self, pos);
@@ -500,4 +500,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs)
500500
exit:
501501
return return_value;
502502
}
503-
/*[clinic end generated code: output=3cf3262c9b157dc1 input=a9049054013a1b77]*/
503+
/*[clinic end generated code: output=4f7490f82427c63b input=a9049054013a1b77]*/

Modules/_io/clinic/bytesio.c.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ _io_BytesIO_read(bytesio *self, PyObject **args, Py_ssize_t nargs, PyObject *kwn
169169
PyObject *return_value = NULL;
170170
Py_ssize_t size = -1;
171171

172-
if (!_PyArg_ParseStack(args, nargs, "|O&:read",
173-
_Py_convert_optional_to_ssize_t, &size)) {
172+
if (!_PyArg_NoStackKeywords("read", kwnames)) {
174173
goto exit;
175174
}
176175

177-
if (!_PyArg_NoStackKeywords("read", kwnames)) {
176+
if (!_PyArg_ParseStack(args, nargs, "|O&:read",
177+
_Py_convert_optional_to_ssize_t, &size)) {
178178
goto exit;
179179
}
180180
return_value = _io_BytesIO_read_impl(self, size);
@@ -204,12 +204,12 @@ _io_BytesIO_read1(bytesio *self, PyObject **args, Py_ssize_t nargs, PyObject *kw
204204
PyObject *return_value = NULL;
205205
Py_ssize_t size = -1;
206206

207-
if (!_PyArg_ParseStack(args, nargs, "|O&:read1",
208-
_Py_convert_optional_to_ssize_t, &size)) {
207+
if (!_PyArg_NoStackKeywords("read1", kwnames)) {
209208
goto exit;
210209
}
211210

212-
if (!_PyArg_NoStackKeywords("read1", kwnames)) {
211+
if (!_PyArg_ParseStack(args, nargs, "|O&:read1",
212+
_Py_convert_optional_to_ssize_t, &size)) {
213213
goto exit;
214214
}
215215
return_value = _io_BytesIO_read1_impl(self, size);
@@ -240,12 +240,12 @@ _io_BytesIO_readline(bytesio *self, PyObject **args, Py_ssize_t nargs, PyObject
240240
PyObject *return_value = NULL;
241241
Py_ssize_t size = -1;
242242

243-
if (!_PyArg_ParseStack(args, nargs, "|O&:readline",
244-
_Py_convert_optional_to_ssize_t, &size)) {
243+
if (!_PyArg_NoStackKeywords("readline", kwnames)) {
245244
goto exit;
246245
}
247246

248-
if (!_PyArg_NoStackKeywords("readline", kwnames)) {
247+
if (!_PyArg_ParseStack(args, nargs, "|O&:readline",
248+
_Py_convert_optional_to_ssize_t, &size)) {
249249
goto exit;
250250
}
251251
return_value = _io_BytesIO_readline_impl(self, size);
@@ -276,13 +276,13 @@ _io_BytesIO_readlines(bytesio *self, PyObject **args, Py_ssize_t nargs, PyObject
276276
PyObject *return_value = NULL;
277277
PyObject *arg = Py_None;
278278

279-
if (!_PyArg_UnpackStack(args, nargs, "readlines",
280-
0, 1,
281-
&arg)) {
279+
if (!_PyArg_NoStackKeywords("readlines", kwnames)) {
282280
goto exit;
283281
}
284282

285-
if (!_PyArg_NoStackKeywords("readlines", kwnames)) {
283+
if (!_PyArg_UnpackStack(args, nargs, "readlines",
284+
0, 1,
285+
&arg)) {
286286
goto exit;
287287
}
288288
return_value = _io_BytesIO_readlines_impl(self, arg);
@@ -347,12 +347,12 @@ _io_BytesIO_truncate(bytesio *self, PyObject **args, Py_ssize_t nargs, PyObject
347347
PyObject *return_value = NULL;
348348
Py_ssize_t size = self->pos;
349349

350-
if (!_PyArg_ParseStack(args, nargs, "|O&:truncate",
351-
_Py_convert_optional_to_ssize_t, &size)) {
350+
if (!_PyArg_NoStackKeywords("truncate", kwnames)) {
352351
goto exit;
353352
}
354353

355-
if (!_PyArg_NoStackKeywords("truncate", kwnames)) {
354+
if (!_PyArg_ParseStack(args, nargs, "|O&:truncate",
355+
_Py_convert_optional_to_ssize_t, &size)) {
356356
goto exit;
357357
}
358358
return_value = _io_BytesIO_truncate_impl(self, size);
@@ -386,12 +386,12 @@ _io_BytesIO_seek(bytesio *self, PyObject **args, Py_ssize_t nargs, PyObject *kwn
386386
Py_ssize_t pos;
387387
int whence = 0;
388388

389-
if (!_PyArg_ParseStack(args, nargs, "n|i:seek",
390-
&pos, &whence)) {
389+
if (!_PyArg_NoStackKeywords("seek", kwnames)) {
391390
goto exit;
392391
}
393392

394-
if (!_PyArg_NoStackKeywords("seek", kwnames)) {
393+
if (!_PyArg_ParseStack(args, nargs, "n|i:seek",
394+
&pos, &whence)) {
395395
goto exit;
396396
}
397397
return_value = _io_BytesIO_seek_impl(self, pos, whence);
@@ -468,4 +468,4 @@ _io_BytesIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
468468
exit:
469469
return return_value;
470470
}
471-
/*[clinic end generated code: output=733795434f838b71 input=a9049054013a1b77]*/
471+
/*[clinic end generated code: output=9e63715414bffb2a input=a9049054013a1b77]*/

Modules/_io/clinic/fileio.c.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ _io_FileIO_read(fileio *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnam
213213
PyObject *return_value = NULL;
214214
Py_ssize_t size = -1;
215215

216-
if (!_PyArg_ParseStack(args, nargs, "|O&:read",
217-
_Py_convert_optional_to_ssize_t, &size)) {
216+
if (!_PyArg_NoStackKeywords("read", kwnames)) {
218217
goto exit;
219218
}
220219

221-
if (!_PyArg_NoStackKeywords("read", kwnames)) {
220+
if (!_PyArg_ParseStack(args, nargs, "|O&:read",
221+
_Py_convert_optional_to_ssize_t, &size)) {
222222
goto exit;
223223
}
224224
return_value = _io_FileIO_read_impl(self, size);
@@ -290,12 +290,12 @@ _io_FileIO_seek(fileio *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnam
290290
PyObject *pos;
291291
int whence = 0;
292292

293-
if (!_PyArg_ParseStack(args, nargs, "O|i:seek",
294-
&pos, &whence)) {
293+
if (!_PyArg_NoStackKeywords("seek", kwnames)) {
295294
goto exit;
296295
}
297296

298-
if (!_PyArg_NoStackKeywords("seek", kwnames)) {
297+
if (!_PyArg_ParseStack(args, nargs, "O|i:seek",
298+
&pos, &whence)) {
299299
goto exit;
300300
}
301301
return_value = _io_FileIO_seek_impl(self, pos, whence);
@@ -347,13 +347,13 @@ _io_FileIO_truncate(fileio *self, PyObject **args, Py_ssize_t nargs, PyObject *k
347347
PyObject *return_value = NULL;
348348
PyObject *posobj = NULL;
349349

350-
if (!_PyArg_UnpackStack(args, nargs, "truncate",
351-
0, 1,
352-
&posobj)) {
350+
if (!_PyArg_NoStackKeywords("truncate", kwnames)) {
353351
goto exit;
354352
}
355353

356-
if (!_PyArg_NoStackKeywords("truncate", kwnames)) {
354+
if (!_PyArg_UnpackStack(args, nargs, "truncate",
355+
0, 1,
356+
&posobj)) {
357357
goto exit;
358358
}
359359
return_value = _io_FileIO_truncate_impl(self, posobj);
@@ -385,4 +385,4 @@ _io_FileIO_isatty(fileio *self, PyObject *Py_UNUSED(ignored))
385385
#ifndef _IO_FILEIO_TRUNCATE_METHODDEF
386386
#define _IO_FILEIO_TRUNCATE_METHODDEF
387387
#endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */
388-
/*[clinic end generated code: output=a4044e2d878248d0 input=a9049054013a1b77]*/
388+
/*[clinic end generated code: output=2c6a5470100a8f10 input=a9049054013a1b77]*/

Modules/_io/clinic/iobase.c.h

Lines changed: 10 additions & 10 deletions

0 commit comments

Comments
 (0)