summaryrefslogtreecommitdiffstats
path: root/Modules/_io
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
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')
-rw-r--r--Modules/_io/_iomodule.c15
-rw-r--r--Modules/_io/clinic/_iomodule.c.h6
-rw-r--r--Modules/_io/clinic/fileio.c.h6
-rw-r--r--Modules/_io/clinic/textio.c.h18
-rw-r--r--Modules/_io/clinic/winconsoleio.c.h6
-rw-r--r--Modules/_io/fileio.c4
-rw-r--r--Modules/_io/textio.c14
-rw-r--r--Modules/_io/winconsoleio.c4
8 files changed, 36 insertions, 37 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.
*/
diff --git a/Modules/_io/clinic/_iomodule.c.h b/Modules/_io/clinic/_iomodule.c.h
index b387384..4d76e33 100644
--- a/Modules/_io/clinic/_iomodule.c.h
+++ b/Modules/_io/clinic/_iomodule.c.h
@@ -280,8 +280,8 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
}
}
if (args[6]) {
- closefd = _PyLong_AsInt(args[6]);
- if (closefd == -1 && PyErr_Occurred()) {
+ closefd = PyObject_IsTrue(args[6]);
+ if (closefd < 0) {
goto exit;
}
if (!--noptargs) {
@@ -407,4 +407,4 @@ _io_open_code(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
exit:
return return_value;
}
-/*[clinic end generated code: output=1f8001287a423470 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=f387eba3f4c0254a input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/fileio.c.h b/Modules/_io/clinic/fileio.c.h
index a925b94..b6e9bd5 100644
--- a/Modules/_io/clinic/fileio.c.h
+++ b/Modules/_io/clinic/fileio.c.h
@@ -116,8 +116,8 @@ _io_FileIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
}
}
if (fastargs[2]) {
- closefd = _PyLong_AsInt(fastargs[2]);
- if (closefd == -1 && PyErr_Occurred()) {
+ closefd = PyObject_IsTrue(fastargs[2]);
+ if (closefd < 0) {
goto exit;
}
if (!--noptargs) {
@@ -466,4 +466,4 @@ _io_FileIO_isatty(fileio *self, PyObject *Py_UNUSED(ignored))
#ifndef _IO_FILEIO_TRUNCATE_METHODDEF
#define _IO_FILEIO_TRUNCATE_METHODDEF
#endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */
-/*[clinic end generated code: output=ff479a26cab0d479 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=27f883807a6c29ae input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h
index 038f0a5..db968e8 100644
--- a/Modules/_io/clinic/textio.c.h
+++ b/Modules/_io/clinic/textio.c.h
@@ -68,8 +68,8 @@ _io_IncrementalNewlineDecoder___init__(PyObject *self, PyObject *args, PyObject
goto exit;
}
decoder = fastargs[0];
- translate = _PyLong_AsInt(fastargs[1]);
- if (translate == -1 && PyErr_Occurred()) {
+ translate = PyObject_IsTrue(fastargs[1]);
+ if (translate < 0) {
goto exit;
}
if (!noptargs) {
@@ -137,8 +137,8 @@ _io_IncrementalNewlineDecoder_decode(nldecoder_object *self, PyObject *const *ar
if (!noptargs) {
goto skip_optional_pos;
}
- final = _PyLong_AsInt(args[1]);
- if (final == -1 && PyErr_Occurred()) {
+ final = PyObject_IsTrue(args[1]);
+ if (final < 0) {
goto exit;
}
skip_optional_pos:
@@ -331,16 +331,16 @@ _io_TextIOWrapper___init__(PyObject *self, PyObject *args, PyObject *kwargs)
}
}
if (fastargs[4]) {
- line_buffering = _PyLong_AsInt(fastargs[4]);
- if (line_buffering == -1 && PyErr_Occurred()) {
+ line_buffering = PyObject_IsTrue(fastargs[4]);
+ if (line_buffering < 0) {
goto exit;
}
if (!--noptargs) {
goto skip_optional_pos;
}
}
- write_through = _PyLong_AsInt(fastargs[5]);
- if (write_through == -1 && PyErr_Occurred()) {
+ write_through = PyObject_IsTrue(fastargs[5]);
+ if (write_through < 0) {
goto exit;
}
skip_optional_pos:
@@ -769,4 +769,4 @@ _io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored))
{
return _io_TextIOWrapper_close_impl(self);
}
-/*[clinic end generated code: output=aecd376eca3cb148 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=73f84b13c343b34b input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/winconsoleio.c.h b/Modules/_io/clinic/winconsoleio.c.h
index 65820a8..df834db 100644
--- a/Modules/_io/clinic/winconsoleio.c.h
+++ b/Modules/_io/clinic/winconsoleio.c.h
@@ -115,8 +115,8 @@ _io__WindowsConsoleIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
}
}
if (fastargs[2]) {
- closefd = _PyLong_AsInt(fastargs[2]);
- if (closefd == -1 && PyErr_Occurred()) {
+ closefd = PyObject_IsTrue(fastargs[2]);
+ if (closefd < 0) {
goto exit;
}
if (!--noptargs) {
@@ -407,4 +407,4 @@ _io__WindowsConsoleIO_isatty(winconsoleio *self, PyObject *Py_UNUSED(ignored))
#ifndef _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
#define _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
#endif /* !defined(_IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF) */
-/*[clinic end generated code: output=08ae244e9a44da55 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=4920e9068e0cf08a input=a9049054013a1b77]*/
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 659297e..d1a183c 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -198,7 +198,7 @@ extern int _Py_open_cloexec_works;
_io.FileIO.__init__
file as nameobj: object
mode: str = "r"
- closefd: bool(accept={int}) = True
+ closefd: bool = True
opener: object = None
Open a file.
@@ -219,7 +219,7 @@ results in functionality similar to passing None).
static int
_io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
int closefd, PyObject *opener)
-/*[clinic end generated code: output=23413f68e6484bbd input=1596c9157a042a39]*/
+/*[clinic end generated code: output=23413f68e6484bbd input=588aac967e0ba74b]*/
{
#ifdef MS_WINDOWS
Py_UNICODE *widename = NULL;
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index 3091f6e..32ab8a4 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -212,7 +212,7 @@ typedef struct {
/*[clinic input]
_io.IncrementalNewlineDecoder.__init__
decoder: object
- translate: int
+ translate: bool
errors: object(c_default="NULL") = "strict"
Codec used when reading a file in universal newlines mode.
@@ -229,7 +229,7 @@ static int
_io_IncrementalNewlineDecoder___init___impl(nldecoder_object *self,
PyObject *decoder, int translate,
PyObject *errors)
-/*[clinic end generated code: output=fbd04d443e764ec2 input=89db6b19c6b126bf]*/
+/*[clinic end generated code: output=fbd04d443e764ec2 input=ed547aa257616b0e]*/
{
if (errors == NULL) {
@@ -484,13 +484,13 @@ _PyIncrementalNewlineDecoder_decode(PyObject *myself,
/*[clinic input]
_io.IncrementalNewlineDecoder.decode
input: object
- final: bool(accept={int}) = False
+ final: bool = False
[clinic start generated code]*/
static PyObject *
_io_IncrementalNewlineDecoder_decode_impl(nldecoder_object *self,
PyObject *input, int final)
-/*[clinic end generated code: output=0d486755bb37a66e input=a4ea97f26372d866]*/
+/*[clinic end generated code: output=0d486755bb37a66e input=90e223c70322c5cd]*/
{
return _PyIncrementalNewlineDecoder_decode((PyObject *) self, input, final);
}
@@ -1023,8 +1023,8 @@ _io.TextIOWrapper.__init__
encoding: str(accept={str, NoneType}) = None
errors: object = None
newline: str(accept={str, NoneType}) = None
- line_buffering: bool(accept={int}) = False
- write_through: bool(accept={int}) = False
+ line_buffering: bool = False
+ write_through: bool = False
Character and line based layer over a BufferedIOBase object, buffer.
@@ -1061,7 +1061,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
const char *encoding, PyObject *errors,
const char *newline, int line_buffering,
int write_through)
-/*[clinic end generated code: output=72267c0c01032ed2 input=72590963698f289b]*/
+/*[clinic end generated code: output=72267c0c01032ed2 input=e6cfaaaf6059d4f5]*/
{
PyObject *raw, *codec_info = NULL;
PyObject *res;
diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c
index 5c1a6dd..d5de64b 100644
--- a/Modules/_io/winconsoleio.c
+++ b/Modules/_io/winconsoleio.c
@@ -235,7 +235,7 @@ winconsoleio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
_io._WindowsConsoleIO.__init__
file as nameobj: object
mode: str = "r"
- closefd: bool(accept={int}) = True
+ closefd: bool = True
opener: object = None
Open a console buffer by file descriptor.
@@ -249,7 +249,7 @@ static int
_io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj,
const char *mode, int closefd,
PyObject *opener)
-/*[clinic end generated code: output=3fd9cbcdd8d95429 input=06ae4b863c63244b]*/
+/*[clinic end generated code: output=3fd9cbcdd8d95429 input=7a3eed6bbe998fd9]*/
{
const char *s;
wchar_t *name = NULL;