I hope this proposal succeeds. I would love to use this feature.
PEP 810 – Explicit lazy imports
21–30 of 247 posts
Re: PEP 810 – Explicit lazy imports
#22What I want is for imports to not suck and be slow. I’ve had projects where it was faster to compile and run C++ than launch and start a Python CLI. It’s so bad.
Re: PEP 810 – Explicit lazy imports
#23Feels like a good feature, with a simple explanation, real world use cases, and a scoped solution (global only, pretty simple keyword). I like it!
Re: PEP 810 – Explicit lazy imports
#24Does this fix the circular imports problem that comes up if you don't structural your programs in a hierarchical way?
This is what I thought of too. I really only know python, do other languages not have that issue? In python it does not seem like a "problem" to me - whenever I have seen circular import issues it is because the code is organized poorly. I worry that this feature will lead to devs "fixing" circular import issues by using lazy imports.
Re: PEP 810 – Explicit lazy imports
#25I know/heard there are "some" (which I haven't seen by the way) libraries that depend on import side effects, but the advantage is much bigger.
First of all, the circular import problem will go away, especially on type hints. Although there was a PEP or recent addition to make the annotation not not cause such issue.
Second and most important of all, is the launch time of Python applications. A CLI that uses many different parts of the app has to wait for all the imports to be done.
The second point becomes a lot painful when you have a large application, like a Django project where the auto reload becomes several seconds. Not only auto reload crawls, the testing cycle is slow as well. Every time you want to run test command, it has to wait several seconds. Painful.
So far the solution has been to do the lazy import by importing inside the methods where it's required. That is something, I never got to like to be honest.
Maybe it will be fixed in Python 4, where the JIT uses the type hints as well /s
Re: PEP 810 – Explicit lazy imports
#26I’m pretty sure there will be new keywords in Python in the future that only solve one thing.
Re: PEP 810 – Explicit lazy imports
#27Re: PEP 810 – Explicit lazy imports
#28 lazily import package.foo
vs
defer import package.foo
Also the grammar is super weird for from imports. lazy from package import foo
vs.
from package defer import foo.Re: PEP 810 – Explicit lazy imports
#29I wish all imports were lazy by default. I know/heard there are "some" (which I haven't seen by the way) libraries that depend on import side effects, but the advantage is much bigger. First of all, the circular import problem will go away, especially on type hints. Although there was a PEP or recent addition to make the annotation not not cause such issue. Second and most important of all, is the launch time of Pyth…