Comment by dataflow
3 days ago
> This pattern, for example, can’t be lazy: try: import numpy; except ModuleNotFoundError: ...
Wait, that seems bad. These kinds of modules (especially numba) are often exactly the ones that you want to delay importing. Why not provide a way to check the existence at import time? How are you supposed to handle nonexistence in that case?
> The error here will move to the first usage of something from numpy. There is a semi-lazy alternative:
...crash?
Seriously: crash if your dependencies aren't available. There are better ways to do optional dependencies. ImportError ain't it.
What is the right way to handle an optional dependency?
https://packaging.python.org/en/latest/guides/writing-pyproj...
1 reply →
I think this import flow tends to be the canonical one.
I might recommend doing something like importing from something like `numpy.version` (or some other "random" very small utils package) so that the work done on file load is still fairly small.
4 replies →