Skip to content

native lazy imports with PEP810 - #172

Draft
benedikt-bartscher wants to merge 8 commits into
scientific-python:mainfrom
benedikt-bartscher:add-native-python-3.15-support
Draft

benedikt-bartscher wants to merge 8 commits into
scientific-python:mainfrom
benedikt-bartscher:add-native-python-3.15-support

Conversation

@benedikt-bartscher

Copy link
Copy Markdown
Contributor

No description provided.

@stefanv stefanv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread README.md Outdated

### Native lazy imports on Python 3.15+

Python 3.15 introduced native lazy imports

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please edit this paragraph to be more concise and readable?

@benedikt-bartscher

Copy link
Copy Markdown
Contributor Author

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
benedikt-bartscher marked this pull request as draft September 4, 2026 07:09
@stefanv

stefanv commented Sep 10, 2026

Copy link
Copy Markdown
Member

@benedikt-bartscher I'll probably put out a new release soon, in case you're interested in getting this in.

@stefanv

stefanv commented Sep 10, 2026

Copy link
Copy Markdown
Member

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

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.38%. Comparing base (bdcafab) to head (04dd053).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@benedikt-bartscher
benedikt-bartscher force-pushed the add-native-python-3.15-support branch from c795182 to b439cd6 Compare September 11, 2026 14:52
@stefanv stefanv added the type: Enhancement New feature or request label Sep 15, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: Enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants