Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Various style fixes. #10569

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
Feb 25, 2018
Merged

Various style fixes. #10569

merged 1 commit into from
Feb 25, 2018

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Feb 23, 2018

PR Summary

Closes (among other things) item 3 of #10556.

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

@anntzer anntzer added this to the v3.0 milestone Feb 23, 2018
if key.startswith('l'): continue
pw, ph = papersize[key]
if (w < pw) and (h < ph): return key
for key, (pw, ph) in sorted(papersize.items())[::-1]:
Copy link
Member

Choose a reason for hiding this comment

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

Use sorted(..., reverse=True)?

if type == 'rotate' and value == (0.0,):
if (type == 'scale' and (value == (1.0,) or value == (1.0, 1.0))
or type == 'translate' and value == (0.0, 0.0)
or type == 'rotate' and value == (0.0,)):
Copy link
Member

Choose a reason for hiding this comment

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

leave out all the zeros after the decimal point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually even the decimal point is not necessary ((1., 1.) == (1, 1))

@@ -252,10 +250,8 @@ def random_ports(port, n):
raise
Copy link
Member

Choose a reason for hiding this comment

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

maybe slightly more readable:

            try:
                app.listen(port, cls.address)
                cls.port = port
                break
            except socket.error as e:
                if e.errno != errno.EADDRINUSE:
                    raise

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tend to prefer the try really only surrounding the potentially exception-raising code.

Copy link
Member

Choose a reason for hiding this comment

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

ok.

@@ -1557,12 +1557,10 @@ def _determine_order(self, totals):
A helper function to determine the highest order of glue
Copy link
Member

Choose a reason for hiding this comment

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

Should be a staticmethod.

break
return o
return i
Copy link
Member

Choose a reason for hiding this comment

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

I'd return 0 here and return i instead of break.

@anntzer
Copy link
Contributor Author

anntzer commented Feb 24, 2018

all comments handled

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

conditional on CI pass

name for name, obj in globals().items()
if not name.startswith('_') and name not in exclude
and inspect.isfunction(obj)
and inspect.getmodule(obj) is this_module)
Copy link
Member

Choose a reason for hiding this comment

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

Side note: as an argument to sorted, using a list comprehension is faster than using a bare generator:

In [10]: timeit sorted([i for i in range(100)])
7.52 µs ± 119 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

In [11]: timeit sorted(i for i in range(100))
10.1 µs ± 223 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

Of course, it doesn't matter unless one is dealing with a large number of items or calls.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I'm puzzled how that can be the case. https://bugs.python.org/issue32945

"tick_levels": dict(left=[], bottom=[], right=[], top=[]),
"tick_locs": dict(left=[], bottom=[], right=[], top=[]),
"lines": [],
}
Copy link
Member

Choose a reason for hiding this comment

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

This is OK, but I have a mild style preference for using dict() whenever possible:

gi = dict(values=[],
          levels=[],
          tick_levels=dict(left=[], bottom=[], right=[], top=[]),
          #etc.
         )

@efiring efiring merged commit 34aee94 into matplotlib:master Feb 25, 2018
@anntzer anntzer deleted the style branch February 25, 2018 08:08
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.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.