MNT: reduce number of implicit imports from toplevel __init__.py #26017
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Either hide or defer imports from the toplevel import
PR summary
When thinking about #26016 / #22247 I started to look into which of our public modules we import via #import matplotlib` and if that could be reduced further.
With this branch we are down to:
we need rcsetup to build
rcParams
,cbook
is used everywhere, nadft2font
is imported incheck_versions()
to work around a wheel-related issue with kiwisolver + msft.This has a minimal effect on import time (.01s of seconds) and as soon as you import anything else (e.g.
import matplotlib.figure
the most minimal thing you need to do ~anything with Matplotlib) the import list is 86 long so at best this defers a bit of work.I'm torn if this is a good idea, I was curious what it would take to reduce the imports, so this is an answer to that. Most of the change is moving things out of
colors.py
to avoid the import ofmatplotlib.scale
.If we take this, then it should be with the understanding that this is the first step in trimming our imports or we should reject this as an indication that we are not going to worry about this sort of micro-optimizations.
PR checklist