You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
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?
The text was updated successfully, but these errors were encountered:
timhoffm
changed the title
[MNT]: Cleanup internal import dependencies and setup of structures at import-time
[MNT]: Cleanup internal import dependencies and initialization logic
Mar 26, 2025
(With missing emoji-fonts, I hope that the first option is thumbs up...)
Seems to make sense! I guess the first thing is to add the mechanism to run _mpl_init() and then one can do this step-by-step and figure out any complications as one realizes them? Also, even if this turns out to be not fully workable, it will still be an improvement when it can be applied (it can probably be applied everywhere though).
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
_mpl_init()
function in that module. ( (e.g. it's tricky for colormaps because the colormaps are injected as globals into the cm module)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?
The text was updated successfully, but these errors were encountered: