mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
gh-82626: Emit a warning when bool is used as a file descriptor (GH-111275)
This commit is contained in:
parent
09096a1647
commit
652fbf88c4
11 changed files with 75 additions and 0 deletions
|
|
@ -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()) {
|
||||
|
|
|
|||
|
|
@ -119,6 +119,13 @@ faulthandler_get_fileno(PyObject **file_ptr)
|
|||
}
|
||||
}
|
||||
else if (PyLong_Check(file)) {
|
||||
if (PyBool_Check(file)) {
|
||||
if (PyErr_WarnEx(PyExc_RuntimeWarning,
|
||||
"bool is used as a file descriptor", 1))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
fd = PyLong_AsInt(file);
|
||||
if (fd == -1 && PyErr_Occurred())
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -969,6 +969,13 @@ _fd_converter(PyObject *o, int *p)
|
|||
int overflow;
|
||||
long long_value;
|
||||
|
||||
if (PyBool_Check(o)) {
|
||||
if (PyErr_WarnEx(PyExc_RuntimeWarning,
|
||||
"bool is used as a file descriptor", 1))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
PyObject *index = _PyNumber_Index(o);
|
||||
if (index == NULL) {
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue