Skip to content

[MNT]: Cleanup internal import dependencies and initialization logic #29813

@timhoffm

Description

@timhoffm

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions