Skip to content

Commit 8e8db35

Browse files
committed
bpo-34070: only check for isatty when buffering < 0
1 parent bc9aa81 commit 8e8db35

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Make sure to only check if the handle is a tty, when opening
2+
a file with ``buffering=-1``.

Modules/_io/_iomodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
241241

242242
char rawmode[6], *m;
243243
int line_buffering, is_number;
244-
long isatty;
244+
long isatty = 0;
245245

246246
PyObject *raw, *modeobj = NULL, *buffer, *wrapper, *result = NULL, *path_or_fd = NULL;
247247

@@ -388,7 +388,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
388388
goto error;
389389

390390
/* buffering */
391-
{
391+
if (buffering < 0) {
392392
PyObject *res = _PyObject_CallMethodId(raw, &PyId_isatty, NULL);
393393
if (res == NULL)
394394
goto error;
@@ -398,7 +398,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
398398
goto error;
399399
}
400400

401-
if (buffering == 1 || (buffering < 0 && isatty)) {
401+
if (buffering == 1 || isatty) {
402402
buffering = -1;
403403
line_buffering = 1;
404404
}

0 commit comments

Comments
 (0)