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

Skip to content

Make flake8 exceptions explicit #11613

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 4 commits into from
Jul 10, 2018
Merged

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Jul 10, 2018

PR Summary

We have some globs being used to define exceptions over a great many files. This instead makes them explicit. There are three reasons: 1) when running flake8 on a single file, it won't trigger the superfluous warning if the globs are not applicable; 2) it will be easier to remove these exceptions piecemeal as things are fixed, and 3) new files can't accidentally add to the exceptions.

Also, fix the spurious exception issue in master.

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

@QuLogic
Copy link
Member Author

QuLogic commented Jul 10, 2018

PS, while this may seem like a long list, there are only 190 of 565, ~33% of the files matched by the glob that actually require the exception.

@tacaswell tacaswell added this to the v3.0 milestone Jul 10, 2018
@tacaswell tacaswell merged commit 734c194 into matplotlib:master Jul 10, 2018
@QuLogic QuLogic deleted the flake8-explicit branch July 10, 2018 02:28
@jklymak
Copy link
Member

jklymak commented Jul 10, 2018

OK, as a counterexample E402 triggers on on all the example files where we have references because we call import matplotlib.

Do we

  1. not want to have these reference sections?
  2. want to move the matplotlib import to the top
  3. make E402 an exception for all of examples?

I'd vote for 3, but this PR precludes that.

#############################################################################
#
# ------------
#
# References
# """"""""""
#
# The use of the following functions and methods is shown in this example:

import matplotlib
matplotlib.axes.Axes.inset_axes_from_bounds
matplotlib.axes.Axes.indicate_inset_zoom
matplotlib.axes.Axes.imshow

@tacaswell
Copy link
Member

I am inclined to skip checking E402 everywhere (which will greatly reduce this list).

@jklymak
Copy link
Member

jklymak commented Jul 10, 2018

OK. Done at #11621

@QuLogic
Copy link
Member Author

QuLogic commented Jul 10, 2018

Or instead of exceptions, add # noqa on the import. But I don't like these hacks, I'd prefer if we get sphinx-gallery to do this for us.

@jklymak
Copy link
Member

jklymak commented Jul 10, 2018

The problem is that sphinx-gallery has no way to drill down the axes stack for us because of how we've structured it. ping @ImportanceOfBeingErnest @timhoffm @fredrik-1 who seem to understand sphinx-gallery quite well. But the above was the soln we came to. I'm not horribly opposed to #noqa though for this little helper section...

@ImportanceOfBeingErnest
Copy link
Member

I guess one could in some (yet to be determined way) hack into sphinx gallery and let it produce all examples with #noqa. But it's really odd to have this mysterious (at least to most users looking at matplotlib examples) line in the code.

I would personally vote for skipping the import checks for the examples. Even without the issue of the Reference sections, there are probably enough cases where some import should only occur late in the example. A global ignore for the examples (and tutorials) folder would make the list significantly shorter and prevent having to add an entry for each new example.

I cannot judge if for the rest of the code base it makes sense to ignore E402 completely or on a by-file-basis.

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.

4 participants