-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Small cleanups. #12899
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
Small cleanups. #12899
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -360,14 +360,14 @@ def is_hashable(obj): | |
|
||
|
||
def is_writable_file_like(obj): | ||
"""return true if *obj* looks like a file object with a *write* method""" | ||
"""Return whether *obj* looks like a file object with a *write* method.""" | ||
return callable(getattr(obj, 'write', None)) | ||
|
||
|
||
def file_requires_unicode(x): | ||
""" | ||
Returns `True` if the given writable file-like object requires Unicode | ||
to be written to it. | ||
Returns whether the given writable file-like object requires Unicode to be | ||
written to it. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I like the original wording a bit better because it states what is returned, rather than implying a boolean result via the word "whether", which might be confusing for non-english-native readers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A quick grep shows that there's a lot of places where we're using |
||
""" | ||
try: | ||
x.write(b'') | ||
|
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.
Can we not clobber
file
like this, please?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.
Also, when reassigning a variable within a context like this, I don't think the close() gets called on the new object because the context manager is holding a reference to the original object.
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.
Clobbering what?
file
is not a builtin (... anymore). And I'd say it's a much nicer variable name thanfh
...The fact that the codec writer doesn't get closed doesn't matter (and anyways it will get closed by the GC), what matters is that the file itself gets closed.
prints
so the file is indeed closed before the contextmanager is exited.