summaryrefslogtreecommitdiffstats
path: root/Modules/_io/_iomodule.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-12-03 19:52:21 (GMT)
committerGitHub <noreply@github.com>2022-12-03 19:52:21 (GMT)
commita87c46eab3c306b1c5b8a072b7b30ac2c50651c0 (patch)
tree92c0ebdb6abd303ea967c0bd999d839a98f84494 /Modules/_io/_iomodule.c
parentc68573b339320409b038501fdd7d4f8a56766275 (diff)
downloadcpython-a87c46eab3c306b1c5b8a072b7b30ac2c50651c0.zip
cpython-a87c46eab3c306b1c5b8a072b7b30ac2c50651c0.tar.gz
cpython-a87c46eab3c306b1c5b8a072b7b30ac2c50651c0.tar.bz2
bpo-15999: Accept arbitrary values for boolean parameters. (#15609)
builtins and extension module functions and methods that expect boolean values for parameters now accept any Python object rather than just a bool or int type. This is more consistent with how native Python code itself behaves.
Diffstat (limited to 'Modules/_io/_iomodule.c')
-rw-r--r--Modules/_io/_iomodule.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c
index 121d961..af5950c 100644
--- a/Modules/_io/_iomodule.c
+++ b/Modules/_io/_iomodule.c
@@ -59,7 +59,7 @@ PyDoc_STRVAR(module_doc,
" I/O classes. open() uses the file's blksize (as obtained by os.stat) if\n"
" possible.\n"
);
-
+
/*
* The main open() function
@@ -74,7 +74,7 @@ _io.open
encoding: str(accept={str, NoneType}) = None
errors: str(accept={str, NoneType}) = None
newline: str(accept={str, NoneType}) = None
- closefd: bool(accept={int}) = True
+ closefd: bool = True
opener: object = None
Open file and return a stream. Raise OSError upon failure.
@@ -196,7 +196,7 @@ static PyObject *
_io_open_impl(PyObject *module, PyObject *file, const char *mode,
int buffering, const char *encoding, const char *errors,
const char *newline, int closefd, PyObject *opener)
-/*[clinic end generated code: output=aefafc4ce2b46dc0 input=5bb37f174cb2fb11]*/
+/*[clinic end generated code: output=aefafc4ce2b46dc0 input=cd034e7cdfbf4e78]*/
{
unsigned i;
@@ -204,8 +204,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
int text = 0, binary = 0;
char rawmode[6], *m;
- int line_buffering, is_number;
- long isatty = 0;
+ int line_buffering, is_number, isatty = 0;
PyObject *raw, *modeobj = NULL, *buffer, *wrapper, *result = NULL, *path_or_fd = NULL;
@@ -345,9 +344,9 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
PyObject *res = PyObject_CallMethodNoArgs(raw, &_Py_ID(isatty));
if (res == NULL)
goto error;
- isatty = PyLong_AsLong(res);
+ isatty = PyObject_IsTrue(res);
Py_DECREF(res);
- if (isatty == -1 && PyErr_Occurred())
+ if (isatty < 0)
goto error;
}
@@ -509,7 +508,7 @@ _io_open_code_impl(PyObject *module, PyObject *path)
{
return PyFile_OpenCodeObject(path);
}
-
+
/*
* Private helpers for the io module.
*/