native lazy imports with PEP810 - #172
benedikt-bartscher wants to merge 8 commits into
Conversation
stefanv
left a comment
There was a problem hiding this comment.
Thanks, @benedikt-bartscher. This PR looks roughly right to me, but with lazy loading the devil often lies in the details. Presumably, this is an AI assisted contribution; have you tested it exhaustively?
I also noted some AI-flavor text in the README, and asked if you would mind editing that down to be a bit more parsable.
|
|
||
| ### Native lazy imports on Python 3.15+ | ||
|
|
||
| Python 3.15 introduced native lazy imports |
There was a problem hiding this comment.
Could you please edit this paragraph to be more concise and readable?
|
Hi @stefanv thanks for your review. Yes, this is written with AI contribution. I have tested it in some big projects, which we are using on a daily basis. I will keep polishing the PR over the weekend. |
|
@benedikt-bartscher I'll probably put out a new release soon, in case you're interested in getting this in. |
|
As a curiosity, do you know of an advantage of this approach? My intuition is that it should be "safer", but it would be helpful to have a concrete example. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #172 +/- ##
==========================================
+ Coverage 96.72% 97.38% +0.66%
==========================================
Files 1 1
Lines 122 153 +31
Branches 23 30 +7
==========================================
+ Hits 118 149 +31
Misses 1 1
Partials 3 3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
c795182 to
b439cd6
Compare
Drop the accidentally committed .coverage database and uv.lock, and ignore coverage artifacts. The .pre-commit-config.yaml reformatting is kept: it is what the pinned prettier 3.9.4 produces, and main is not clean under its own hook without it. Assisted-by: claude-code:claude-opus-5
The syntax is absent from 3.15.0a6 and present in 3.15.0rc2, so a version comparison enables the native path on builds that cannot compile a `lazy` statement. Compile a probe statement at import time instead. Assisted-by: claude-code:claude-opus-5
Assert against types.LazyImportType rather than a proxy repr name, and add tests for `lazy from pkg import sub` --- which resolves a name that is itself still bound to the proxy being resolved --- and for a function shadowed by the subpackage its module lives in. Assisted-by: claude-code:claude-opus-5
Drop the return value nothing consulted and describe the fallback in the docstring instead, note why submodules are sorted but attributes are not, and keep exec() from leaving __builtins__ in the package namespace. Assisted-by: claude-code:claude-opus-5
Lead with the two behavior differences users can observe, and record the fallback when lazy imports are disabled. Assisted-by: claude-code:claude-opus-5
No description provided.