summaryrefslogtreecommitdiffstats
path: root/Modules/_io
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-02-05 20:51:11 (GMT)
committerGitHub <noreply@github.com>2024-02-05 20:51:11 (GMT)
commit652fbf88c4c422ff17fefd4dcb5e06b5c0e26e74 (patch)
tree61b36dd4f458619c68bbee592bade7ed18993dda /Modules/_io
parent09096a1647913526a3d4fa69a9d2056ec82a8f37 (diff)
downloadcpython-652fbf88c4c422ff17fefd4dcb5e06b5c0e26e74.zip
cpython-652fbf88c4c422ff17fefd4dcb5e06b5c0e26e74.tar.gz
cpython-652fbf88c4c422ff17fefd4dcb5e06b5c0e26e74.tar.bz2
gh-82626: Emit a warning when bool is used as a file descriptor (GH-111275)
Diffstat (limited to 'Modules/_io')
-rw-r--r--Modules/_io/fileio.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 9cf268c..6bb156e 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -269,6 +269,13 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
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()) {