gh-115538: Emit warning when use bool as fd in _io.WindowsConsoleIO (GH-116925)

This commit is contained in:
AN Long 2024-03-18 19:48:50 +08:00 committed by GitHub
parent 43c9d6196a
commit cd2ed91780
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 0 deletions

View file

@ -298,6 +298,13 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj,
self->fd = -1;
}
if (PyBool_Check(nameobj)) {
if (PyErr_WarnEx(PyExc_RuntimeWarning,
"bool is used as a file descriptor", 1))
{
return -1;
}
}
fd = PyLong_AsInt(nameobj);
if (fd < 0) {
if (!PyErr_Occurred()) {