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.
doesn't `from scipy import ...` help with memory?
Working to Make Python Lazy
11–20 of 21 posts
Re: Working to Make Python Lazy
#12Good feature but god I hate there’s a whole new keyword for a minor modification on an existing concept. Very unnecessary.
> As soft keywords, their use in the grammar is possible while still preserving compatibility with existing code that uses these names as identifier names.
Re: Working to Make Python Lazy
#13Re: Working to Make Python Lazy
#14Re: Working to Make Python Lazy
#15Re: Working to Make Python Lazy
#16Earlier quoted context omitted.
What is the right way to handle an optional dependency?
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.
What would that be for numba?
Re: Working to Make Python Lazy
#17Earlier quoted context omitted.
...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?
Re: Working to Make Python Lazy
#18Earlier quoted context omitted.
What is the right way to handle an optional dependency?
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.
Re: Working to Make Python Lazy
#19Earlier quoted context omitted.
What is the right way to handle an optional dependency?
https://packaging.python.org/en/latest/guides/writing-pyproj...
Also, you need something that works for simple one-file scripts, not just a whole package or project.
Re: Working to Make Python Lazy
#20Earlier quoted context omitted.
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.
Common? Yes. Canonical/ideal? No. Optional dependency specifiers in your package metadata is a much better way to go. You can use those even if you don't publish your package as an artifact; `pip install -e .[optional-thing]` should work, or can be made to, easily.
"Oh you don't have optional dependency? Then do X" needs to happen at runtime right?