Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Open
Labels
Description
Summary
There's a delicate dependency on who goes first in the import order because we couple module dependencies (imports) and intialization (code execution at import).
See e.g.#29808 (comment)
Proposed fix
I think we can make this simpler by applying the following rules
- no submodule is allowed to run intialization code (e.g. loading the colormaps) as part of their import
- initialization should be lazy if possible
- if lazy initialization is not possible, the initalization code must be placed in a
_mpl_init()
function in that module. ( (e.g. it's tricky for colormaps because the colormaps are injected as globals into the cm module) - only the top-level
matplotlib
module is allowed to call._mpl_init()
of the submodules.
This way, we can decouple initialization from import and have one central place that orchestrates the initialization.
What do you think?