-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-34070: only check for isatty when buffering < 0 #8187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. When your account is ready, please add a comment in this pull request Thanks again for your contribution, we look forward to reviewing it! |
CLA signed. |
Would be nice to add tests. Python implementation in |
I'll look into tests. The Python implementation in 209 │ try:
210 │ line_buffering = False
211 │ if buffering == 1 or buffering < 0 and raw.isatty():
212 │ buffering = -1
213 │ line_buffering = True Since it is left to right. But maybe I am missing something else here? Regarding CLA: It is signed, I got the copy via E-Mail and my Github account is linked in the Python Bugtracker .. I'll double check it again (maybe it takes a while?). Also regarding the Misc/News, is that worth a news entry, it's just a rather small bugfix/improvement? |
A news entry may save hours for somebody if his program will fail when run on different computer with older Python because of this change. The Python implementation looks fine to me too. |
@@ -388,7 +388,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, | |||
goto error; | |||
|
|||
/* buffering */ | |||
{ | |||
if (buffering < 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to have an else block to initialize isatty variable, even if it's not used in practice. ("else { isatty = 0; }"). Or initialize the variable to 0 when it's declared?
It should prevent warning from dummy compilers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or add
if (isatty) {
buffering = 1;
}
and simplify the condition (buffering == 1 || (buffering < 0 && isatty))
below to just (buffering == 1)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed. isatty
is now initialized and the redundant buffering < 0
below has been removed.
I changed the code you commented on, I turned the now redundant I also added a news entry, I hope that is proper English and makes sense for a bystander. I am still having troubles with writing tests for this though. My initial idea was to replace the FileIO = self.io.FileIO
class SpyFileIO(FileIO):
_isatty = False
def isatty(self):
SpyFileIO._isatty = True
return False
self.io.FileIO = SpyFileIO
try:
f = self.open(TESTFN, 'w', buffering=-1)
finally:
self.io.FileIO = FileIO
f.close()
self.assertTrue(SpyFileIO._isatty) This works fine for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM without tests. Thanks @Dav1dde!
Just a small formatting nit.
@@ -0,0 +1,2 @@ | |||
Make sure to only check if the handle is a tty, when opening | |||
a file with `buffering=-1`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use double backquotes:
``buffering=-1``
This is a reStructuredText, not Markdown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Sorry about that, haven't been doing enough Python recently :(
Any news on this? Anything I should do? |
https://bugs.python.org/issue34070
Only check for isatty when buffering actually requires the check (buffering < 0)
https://bugs.python.org/issue34070