Skip to content

Commit eabea36

Browse files
committed
pythongh-115538: Emit warning when use bool as fd in _io.WindowsConsoleIO
1 parent b8d808d commit eabea36

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:class:`_io.WindowsConsoleIO` now emit a warning if a boolean value is
2+
passed as a filedescriptor argument.

Modules/_io/winconsoleio.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,13 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj,
298298
self->fd = -1;
299299
}
300300

301+
if (PyBool_Check(nameobj)) {
302+
if (PyErr_WarnEx(PyExc_RuntimeWarning,
303+
"bool is used as a file descriptor", 1))
304+
{
305+
return -1;
306+
}
307+
}
301308
fd = PyLong_AsInt(nameobj);
302309
if (fd < 0) {
303310
if (!PyErr_Occurred()) {

0 commit comments

Comments
 (0)