a backport of lazy imports to python<3.15
Project description
- courtesy of pycon us 2026 steering council presentation
NO
... unless
please don't use this
no seriously. I do not need another joke package of mine to be deemed "critical" to pypi 1
ok how do I use it
pip install future-lazy-imports- add
# -*- coding: future-lazy-imports -*-to the top of your file (second line if you have a shebang) - use
lazy import ...andlazy from ...as normal!
# -*- coding: future-lazy-imports -*-
lazy from asyncio import run
async def hello():
print('hello hello world!')
def main():
run(hello()) # lazily imported!
if __name__ == '__main__':
raise SystemExit(main())
$ time python3 t.py
hello hello world!
real 0m0.064s
user 0m0.061s
sys 0m0.007s
$ time python3 -c 'import t'
real 0m0.027s
user 0m0.023s
sys 0m0.005s
wow!
problems
this doesn't actually implement the PEP, notably __lazy_imports__ doesn't
work also this adds a little bit of overhead to every function (since we don't
have the freedom to add code to LOAD_GLOBAL) and I'm pretty sure lambda
doesn't work ¯\_(ツ)_/¯
sometimes stacktraces point to the wrong line number (if your function starts with a block statement)
see also please don't use this
-
with almost a million downloads per month and 45M+ total ↩
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file future_lazy_imports-1.0.1.tar.gz.
File metadata
- Download URL: future_lazy_imports-1.0.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d466ba7d65a83aa7b02fcd2b99617ecd821c94d99698dc359d5958efee469363
|
|
| MD5 |
478b1899e58a599f61be136aa1f854e1
|
|
| BLAKE2b-256 |
400d3cdbba14a5cb95c0d3e647ffc2550b7e274d8ea7ff0f49fd488caaf0d03c
|
File details
Details for the file future_lazy_imports-1.0.1-py3-none-any.whl.
File metadata
- Download URL: future_lazy_imports-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57a8c8691467db2a39e14126a5e034c32357910fcab9b5c2f039f694aa8143f4
|
|
| MD5 |
e7532954607811c562b3f2564216d7b9
|
|
| BLAKE2b-256 |
ebf21083a4166e6dc642831f942e37851d9561b19fdd3c71c7e20ee6654c0381
|