Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 1 commit into from
Jan 15, 2018
Merged

Minor cleanups. #10248

merged 1 commit into from
Jan 15, 2018

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jan 14, 2018

PR Summary

  • in backend_ps: when writing to a unicode file, no need to first read the entire tempfile in memory and then decode it; just do everything in one step.
  • in type1font: str.split() already strips spaces at the edges of the string (see https://docs.python.org/3/library/stdtypes.html#str.split).

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

Copy link
Member

@efiring efiring left a 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:
Copy link
Member

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.

Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

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

OK

Copy link
Member

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.

Copy link
Contributor Author

@anntzer anntzer Jan 15, 2018

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.

@efiring efiring merged commit c46525a into matplotlib:master Jan 15, 2018
@QuLogic QuLogic added this to the v2.2 milestone Jan 15, 2018
@anntzer anntzer deleted the cleanup branch January 15, 2018 03:13
@anntzer anntzer mentioned this pull request Jan 15, 2018
6 tasks
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants