-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Minor cleanups. #10248
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
Minor cleanups. #10248
Conversation
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.
OK apart from a readability recommendation.
outfile.write(fh.read()) | ||
with (io.open(tmpfile, 'r', encoding='latin-1') | ||
if file_requires_unicode(outfile) | ||
else io.open(tmpfile, 'rb')) as fh: |
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.
At the risk of bikeshedding... I find this 3-line construct a bit of a trip hazard when reading. How about this:
if file_requires_unicode(outfile):
kwd = dict(mode='r', encoding='latin-1')
else:
kwd = dict(mode='rb')
with io.open(tmpfile, **kwd) as fh:
Or if you want to reduce the line count:
kwd = (dict(mode='r', encoding='latin-1') if file_requires_unicode(outfile)
else dict(mode='rb'))
with io.open(tmpfile, **kwd) as fh:
The latter option is no longer than your original, and to me, much more readable. I haven't checked, but I hope it doesn't fall afoul of the line length limit.
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.
Yeah, I totally agree w/ this but thought maybe I was being an anti-fancy-python-tricks stick-in-the-mud
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.
new version seems a reasonable compromise?
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.
OK
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.
Was this actually changed? It's not marked outdated.
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.
Ah, sorry. There were two instances of it, only changed one of them. Will make a separate PR.
PR Summary
PR Checklist