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

Skip to content

Remove unused imports in examples #11651

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 2 commits into from
Jul 13, 2018
Merged

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Jul 13, 2018

PR Summary

Because extra imports make things look less simple, and simple is clearer, I think. Also, annotate the reason for the Axes3D import, which is generally non-obvious unless you happen to be looking at the one example with a comment about it.

PR Checklist

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

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.

Semi off-topic. Why do users have to explicitly import Axes3D. Couldn’t we make that implicitly when we encounter a projection=3d?

@ImportanceOfBeingErnest
Copy link
Member

from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import

As commented elsewhere already, something like # noqa does not makes things very clear to people who do not know about flake (which I suppose is the majority of matplotlib users). Instead, flake can just be set to ignore F401 in all examples from the mplot3d section of the gallery.

An alternative would be to change the examples to actually use the import, as pointed out here

from mpl_toolkits.mplot3d import Axes3D
ax = fig.gca(projection=Axes3D.name)

# or

fig, ax = plt.subplots(subplot_kw=dict(projection=Axes3D.name))

@QuLogic
Copy link
Member Author

QuLogic commented Jul 13, 2018

flake8 does ignore F401 in examples (in fact, it ignores it everywhere, which I dislike). I added these on purpose as a best practice, along with the explanatory comment. But I do like the idea of just using the import; I suppose that sort of comes back to how we answer @timhoffm's question.

@jklymak
Copy link
Member

jklymak commented Jul 13, 2018

I don't think flake8 is currently ignoring E402 everywhere. Thats what #11621 proposes...

@QuLogic
Copy link
Member Author

QuLogic commented Jul 13, 2018

This is about F401, not E402.

@jklymak
Copy link
Member

jklymak commented Jul 13, 2018

Ooops! Sorry

@NelleV NelleV merged commit 66d2282 into matplotlib:master Jul 13, 2018
@NelleV
Copy link
Member

NelleV commented Jul 13, 2018

Thanks @QuLogic !

@QuLogic QuLogic deleted the example-imports branch July 13, 2018 17:04
@QuLogic QuLogic added this to the v3.0 milestone Jul 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants