PEP 810 – Explicit lazy imports
peps.python.org
PEP 810 – Explicit lazy imports
1–10 of 247 posts
Re: PEP 810 – Explicit lazy imports
#2Feels 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
#3I wonder how much things would break if all imports were lazy by default.
Re: PEP 810 – Explicit lazy imports
#4I wonder how much things would break if all imports were lazy by default.
Maybe nothing would break ?
edit: ok well "xxx in sys.modules" would indeed be a problem
Re: PEP 810 – Explicit lazy imports
#5That seems really great, .moving imports in-line for CLI tools startup and test discovery has always been a pain.
Re: PEP 810 – Explicit lazy imports
#6For posterity, as the submitted link seems temporary: https://github.com/python/peps/pull/4622
Re: PEP 810 – Explicit lazy imports
#7Re: PEP 810 – Explicit lazy imports
#8Wake me up when we can import a module by relative file path.
Re: PEP 810 – Explicit lazy imports
#9Feels like a good feature, with a simple explanation, real world use cases, and a scoped solution (global only, pretty simple keyword). I like it!
Yeah, I think this is one of the cleanest PEPs to come around in quite a while, at least from the userspace perspective. Interested to see what happens after the traditional syntax bikeshedding ritual has been completed.
Re: PEP 810 – Explicit lazy imports
#10If anyone's interested I've implemented a fairly user friendly lazy import mechanism in the form of context managers (auto_proxy_import/init) at https://pypi.org/project/lazyimp/ that I use fairly heavily. Syntactically it's just wrapping otherwise unmodified import statements in a with block, so tools 'just work' and it can be easily disabled or told to import eagerly for debugging. It's powered primarily by swapping out the frame's f_builtins in a cext (as it needs more power than importlib hooks provide), but has a lame attempt at a threadsafe pure python version, and a super dumb global hook version.
I was skeptical and cautious with it at first but I've since moved large chunks of my codebase to it - it's caused surprisingly few problems (honestly none besides forgetting to handle some import-time registration in some modules) and the speed boost is addictive.