Rendered at 02:22:47 GMT+0000 (Coordinated Universal Time) with Cloudflare Workers.
dataflow 3 hours 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?
js2 1 hours ago [-]
> The error here will move to the first usage of something from numpy. There is a semi-lazy alternative:
import importlib.util
if importlib.util.find_spec("numpy") is None:
... # whatever you wanted to do if numpy is missing
lazy import numpy
zbentley 2 hours ago [-]
...crash?
Seriously: crash if your dependencies aren't available. There are better ways to do optional dependencies. ImportError ain't it.
dataflow 2 hours ago [-]
What is the right way to handle an optional dependency?
yuriks 3 hours ago [-]
This feature seems really valuable for commandline tools! However this paragraph gave me pause:
> Currently, disabling lazy imports disabled the syntax keyword, which means that you can’t use it for circular imports, type checking, etc.
Imo this is a good thing, laziness shouldn't be semantically important. The ability to force disable laziness while maintaining semantics is important for linting and testing, and more often than not, circular imports are a sign of bad code structure.
mhashemi 3 hours ago [-]
I've got my reservations about lazy imports, but scipy in particular is such a memory hog, I've increasingly been vendoring smaller utilities out of it. Good lazy imports would be a big help.
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?
Seriously: crash if your dependencies aren't available. There are better ways to do optional dependencies. ImportError ain't it.
> Currently, disabling lazy imports disabled the syntax keyword, which means that you can’t use it for circular imports, type checking, etc.
Imo this is a good thing, laziness shouldn't be semantically important. The ability to force disable laziness while maintaining semantics is important for linting and testing, and more often than not, circular imports are a sign of bad code structure.