Skip to content

Commit

Permalink
bpo-34070: open() only checks for isatty if buffering < 0 (GH-8187)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dav1dde authored and vstinner committed Oct 19, 2018
1 parent acef690 commit 8deab96
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
@@ -0,0 +1,2 @@
Make sure to only check if the handle is a tty, when opening
a file with ``buffering=-1``.
6 changes: 3 additions & 3 deletions Modules/_io/_iomodule.c
Expand Up @@ -241,7 +241,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,


char rawmode[6], *m; char rawmode[6], *m;
int line_buffering, is_number; int line_buffering, is_number;
long isatty; long isatty = 0;


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


Expand Down Expand Up @@ -388,7 +388,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
goto error; goto error;


/* buffering */ /* buffering */
{ if (buffering < 0) {
PyObject *res = _PyObject_CallMethodId(raw, &PyId_isatty, NULL); PyObject *res = _PyObject_CallMethodId(raw, &PyId_isatty, NULL);
if (res == NULL) if (res == NULL)
goto error; goto error;
Expand All @@ -398,7 +398,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
goto error; goto error;
} }


if (buffering == 1 || (buffering < 0 && isatty)) { if (buffering == 1 || isatty) {
buffering = -1; buffering = -1;
line_buffering = 1; line_buffering = 1;
} }
Expand Down

1 comment on commit 8deab96

@hashar
Copy link

@hashar hashar commented on 8deab96 Apr 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that one today and thought it could have been my first contribution to cpython. Looking for a preexisting bug report has lead me here.

Anyway, thank you for the small fix :]

Please sign in to comment.