[Python-checkins] bpo-34070: open() only checks for isatty if buffering < 0 (GH-8187)

Victor Stinner webhook-mailer at python.org
Fri Oct 19 18:32:08 EDT 2018


https://github.com/python/cpython/commit/8deab9672554edaf58f91e238cc899463d53f6ea
commit: 8deab9672554edaf58f91e238cc899463d53f6ea
branch: master
author: David Herberth <github at dav1d.de>
committer: Victor Stinner <vstinner at redhat.com>
date: 2018-10-20T00:32:04+02:00
summary:

bpo-34070: open() only checks for isatty if buffering < 0 (GH-8187)

files:
A Misc/NEWS.d/next/Library/2018-07-11-20-51-20.bpo-34070.WpmFAu.rst
M Modules/_io/_iomodule.c

diff --git a/Misc/NEWS.d/next/Library/2018-07-11-20-51-20.bpo-34070.WpmFAu.rst b/Misc/NEWS.d/next/Library/2018-07-11-20-51-20.bpo-34070.WpmFAu.rst
new file mode 100644
index 000000000000..0088c62c0ffb
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-07-11-20-51-20.bpo-34070.WpmFAu.rst
@@ -0,0 +1,2 @@
+Make sure to only check if the handle is a tty, when opening
+a file with ``buffering=-1``.
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c
index 0d8a638f40cf..eedca011d2ed 100644
--- a/Modules/_io/_iomodule.c
+++ b/Modules/_io/_iomodule.c
@@ -241,7 +241,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
 
     char rawmode[6], *m;
     int line_buffering, is_number;
-    long isatty;
+    long isatty = 0;
 
     PyObject *raw, *modeobj = NULL, *buffer, *wrapper, *result = NULL, *path_or_fd = NULL;
 
@@ -388,7 +388,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
         goto error;
 
     /* buffering */
-    {
+    if (buffering < 0) {
         PyObject *res = _PyObject_CallMethodId(raw, &PyId_isatty, NULL);
         if (res == NULL)
             goto error;
@@ -398,7 +398,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
             goto error;
     }
 
-    if (buffering == 1 || (buffering < 0 && isatty)) {
+    if (buffering == 1 || isatty) {
         buffering = -1;
         line_buffering = 1;
     }



More information about the Python-checkins mailing list