Lazy imports for Python
Lazy imports for Python
Posted Sep 8, 2022 10:17 UTC (Thu) by LtWorf (subscriber, #124958)Parent article: Lazy imports for Python
At work we have an internal python tool that to do --version loads 604 files.
This is mostly due to type annotations, that force the imports just to declare a function that uses a certain type.
Importing modules before using them is annoying and requires a lot of discipline, but is only a partial solution
As developer of typedload (like pydantic but better) I am not sure this would help me much. The code imports a bunch of modules to support those types, but the types are referenced so the import happens anyway. I'd have to do a lot of trickery to only reference them when they are actually needed, but that would probably mean that the library would no longer work with cython.
