GeezerVison is showing github.com — gh-161708: Document the __lazy_import__ built-in function by RoryGlenn · Pull Request #161762 · python/cpython
Conversation
RoryGlenn
commented
Nov 10, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Add a reference entry for __lazy_import__ and link it from the language reference for lazy imports. Give the table substitution its own comment explaining the column width and the link to the existing function target.
Validation: a fresh HTML build with warnings treated as errors, Sphinx lint 1.0.2 on both PR documentation files, whitespace checks, and rendered table/link checks passed. Rendering the published source with the same dependencies confirmed unchanged table HTML and anchors. Runtime tests were not rerun for this comment-only follow-up.
Public searches for 161708 and __lazy_import__, across open and closed issues and PRs, found no conflicting documentation contribution; #161716 changes the C docstring separately.
Prepared with OpenAI Codex assistance.
Validation
git diff --check f34ba9882b2bc06a45513d749b1ce421e74e376c HEAD -- Doc/builtins/functions.rst — exit 0
/cache/cpython-pr-161762-docs/bin/sphinx-lint --enable=default-role Doc/builtins/functions.rst Doc/reference/simple_stmts.rst — exit 0
make -C Doc html VENVDIR=/cache/cpython-pr-161762-docs JOBS=4 SPHINXOPTS='--fresh-env --write-all' — exit 0
python3 - <<'PY' from pathlib import Path root = Path('Doc/build/html') functions = (root / 'builtins/functions.html').read_text(encoding='utf-8') reference = (root / 'reference/simple_stmts.html').read_text(encoding='utf-8') assert 'id="func-lazy-import"' in functions assert 'id="lazy_import__"' in functions assert 'href="#func-lazy-import"' in functions assert '../builtins/functions.html#lazy_import__' in reference PY — exit 0
GIT_NO_LAZY_FETCH=1 git diff --check f34ba9882b2bc06a45513d749b1ce421e74e376c HEAD -- Doc/builtins/functions.rst — exit 0
- `python3 - <<'PY'
import html
from pathlib import Path
import re
root = Path('Doc/build/html')
functions = (root / 'builtins/functions.html').read_text(encoding='utf-8')
reference = (root / 'reference/simple_stmts.html').read_text(encoding='utf-8')
assert 'id="func-lazy-import"' in functions
assert 'id="lazy_import__"' in functions
assert 'href="#func-lazy-import"' in functions
assert '../builtins/functions.html#lazy_import__' in reference
table = functions.split('<table', 1)[1].split('', 1)[0]
cells = re.findall(r'<td\b.?', table, flags=re.DOTALL)
assert len(cells) == 4
assert 'href="#func-lazy-import"' in cells[3]
last_column = html.unescape(re.sub(r'<[^>]>', '', cells[3]))
assert last_column.index('import()') < last_column.index('lazy_import()')
visible_text = html.unescape(re.sub(r'<[^>]*>', '', functions))
assert 'Use a substitution because' not in visible_text
PY` — exit 0
Prepared with AI assistance (Codex gpt-6.1-sol). Independent automated review passed for source tree 6f874ac7770b773a2de54fa77c721c894db06e2d. This is automated review. Upstream CI is pending until GitHub reports its result.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
chatgpt-codex-connector[bot] and JadenV15 reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
.. |func-range| replace:: ``range()``
|
|
|
.. |func-bytearray| replace:: ``bytearray()``
|
|
|
.. |func-bytes| replace:: ``bytes()``
|
|
|
.. |func-lazy-import| replace:: ``__lazy_import__()``
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But won't the target end up here? Why is this needed.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The replace:: line only supplies the displayed text, __lazy_import__(). The trailing _ in |func-lazy-import|_ makes that text link to .. _func-lazy-import:, just above the function definition.
I used the same pattern as range() and bytes() because it fits the existing grid. A direct :func: reference can reach the same function, as it does in the language reference, but its markup is too long for that cell with the current spacing. The substitution adds one line under __import__ and preserves the four-column layout.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then please add a comment for that, rather than keep it under the other one.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Automated contribution follow-up (Codex):
Separated func-lazy-import from the preceding substitution group and added its own source comment explaining the table width and the trailing _ link to the existing target. The generated table and anchors are unchanged; the fresh HTML build and Sphinx lint pass.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
| Review |
Status |
Commit |
Review trigger |
| 📝 Code Review |
✅ Completed 2026-11-11T18:40:05.190981Z |
4d01f7f |
Draft marked ready |
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review" or "@codex security review".
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
named by *name*, not an individual member of that module.
|
|
|
|
|
|
If *globals* is omitted or ``None``, the caller's global namespace is used.
|
|
|
Otherwise, it must be a dictionary containing an ``__builtins__`` entry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry to nitpick, but 'an __builtins__ entry' -> 'a __builtins__ entry'
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
|
|
|
The filter installed by :func:`sys.set_lazy_imports_filter` can force an
|
|
|
eager import. If the filter returns false, the function returns the
|
|
|
imported module instead of a lazy proxy.
|
JadenV15
Nov 11, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe specify that the eager module is types.ModuleType? (maybe unnecesssary)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
willingc
Awaiting requested review from willingc
willingc is a code owner
AA-Turner
Awaiting requested review from AA-Turner
AA-Turner is a code owner
+1 more reviewer
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|