Skip to content

Commit 2fe8d1a

Browse files
For "w*" the original error is always overwritten.
1 parent 3a4cdc7 commit 2fe8d1a

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

Modules/_io/clinic/bufferedio.c.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ _io__BufferedIOBase_readinto(PyObject *self, PyObject *arg)
2020
Py_buffer buffer = {NULL, NULL};
2121

2222
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
23+
PyErr_Clear();
24+
_PyErr_BadArgument("readinto", "read-write bytes-like object", arg);
2325
goto exit;
2426
}
2527
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
@@ -55,6 +57,8 @@ _io__BufferedIOBase_readinto1(PyObject *self, PyObject *arg)
5557
Py_buffer buffer = {NULL, NULL};
5658

5759
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
60+
PyErr_Clear();
61+
_PyErr_BadArgument("readinto1", "read-write bytes-like object", arg);
5862
goto exit;
5963
}
6064
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
@@ -192,6 +196,8 @@ _io__Buffered_readinto(buffered *self, PyObject *arg)
192196
Py_buffer buffer = {NULL, NULL};
193197

194198
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
199+
PyErr_Clear();
200+
_PyErr_BadArgument("readinto", "read-write bytes-like object", arg);
195201
goto exit;
196202
}
197203
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
@@ -227,6 +233,8 @@ _io__Buffered_readinto1(buffered *self, PyObject *arg)
227233
Py_buffer buffer = {NULL, NULL};
228234

229235
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
236+
PyErr_Clear();
237+
_PyErr_BadArgument("readinto1", "read-write bytes-like object", arg);
230238
goto exit;
231239
}
232240
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
@@ -496,4 +504,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs)
496504
exit:
497505
return return_value;
498506
}
499-
/*[clinic end generated code: output=ecce6d4ca9143a15 input=a9049054013a1b77]*/
507+
/*[clinic end generated code: output=7ecda6e1be89950a input=a9049054013a1b77]*/

Modules/_io/clinic/bytesio.c.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ _io_BytesIO_readinto(bytesio *self, PyObject *arg)
297297
Py_buffer buffer = {NULL, NULL};
298298

299299
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
300+
PyErr_Clear();
301+
_PyErr_BadArgument("readinto", "read-write bytes-like object", arg);
300302
goto exit;
301303
}
302304
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
@@ -448,4 +450,4 @@ _io_BytesIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
448450
exit:
449451
return return_value;
450452
}
451-
/*[clinic end generated code: output=319d5f4852532292 input=a9049054013a1b77]*/
453+
/*[clinic end generated code: output=dac44db36ab1c27b input=a9049054013a1b77]*/

Modules/_io/clinic/fileio.c.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ _io_FileIO_readinto(fileio *self, PyObject *arg)
157157
Py_buffer buffer = {NULL, NULL};
158158

159159
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
160+
PyErr_Clear();
161+
_PyErr_BadArgument("readinto", "read-write bytes-like object", arg);
160162
goto exit;
161163
}
162164
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
@@ -381,4 +383,4 @@ _io_FileIO_isatty(fileio *self, PyObject *Py_UNUSED(ignored))
381383
#ifndef _IO_FILEIO_TRUNCATE_METHODDEF
382384
#define _IO_FILEIO_TRUNCATE_METHODDEF
383385
#endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */
384-
/*[clinic end generated code: output=13ff9ef76ca044d0 input=a9049054013a1b77]*/
386+
/*[clinic end generated code: output=5dc247fcd8d03ac0 input=a9049054013a1b77]*/

Modules/_io/clinic/winconsoleio.c.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ _io__WindowsConsoleIO_readinto(winconsoleio *self, PyObject *arg)
157157
Py_buffer buffer = {NULL, NULL};
158158

159159
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
160+
PyErr_Clear();
161+
_PyErr_BadArgument("readinto", "read-write bytes-like object", arg);
160162
goto exit;
161163
}
162164
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
@@ -336,4 +338,4 @@ _io__WindowsConsoleIO_isatty(winconsoleio *self, PyObject *Py_UNUSED(ignored))
336338
#ifndef _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
337339
#define _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
338340
#endif /* !defined(_IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF) */
339-
/*[clinic end generated code: output=21005cb3b728c616 input=a9049054013a1b77]*/
341+
/*[clinic end generated code: output=dafe6e700927e4c0 input=a9049054013a1b77]*/

Tools/clinic/clinic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3282,6 +3282,8 @@ def parse_arg(self, argname):
32823282
elif self.format_unit == 'w*':
32833283
return """
32843284
if (PyObject_GetBuffer({argname}, &{paramname}, PyBUF_WRITABLE) < 0) {{{{
3285+
PyErr_Clear();
3286+
_PyErr_BadArgument("{{name}}", "read-write bytes-like object", {argname});
32853287
goto exit;
32863288
}}}}
32873289
if (!PyBuffer_IsContiguous(&{paramname}, 'C')) {{{{

0 commit comments

Comments
 (0)