Skip to content

Commit d95fd85

Browse files
committed
Address open comments
* Update example to add missing import * Add link to lazy keyword * Update documentation
1 parent 7995d56 commit d95fd85

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

Doc/reference/simple_stmts.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,8 +905,9 @@ names remain as lazy proxies until they are accessed.
905905
Example::
906906

907907
lazy import json
908+
import sys
908909

909-
print('json' in sys.modules) # False - module not loaded yet
910+
print('json' in sys.modules) # False - json module not yet loaded
910911

911912
# First use triggers loading
912913
result = json.dumps({"hello": "world"})

Doc/whatsnew/3.15.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ unnecessary dependencies. These approaches work but make code harder to read
9999
and maintain, scatter import statements throughout the codebase, and require
100100
discipline to apply consistently.
101101

102-
Python now provides a cleaner solution through explicit lazy imports using the
103-
new ``lazy`` soft keyword. When you mark an import as lazy, Python defers the
104-
actual module loading until the imported name is first used. This gives you
105-
the organizational benefits of declaring all imports at the top of the file
106-
while only paying the loading cost for modules you actually use.
102+
Python now provides a cleaner solution through explicit :keyword:`lazy` imports
103+
using the new ``lazy`` soft keyword. When you mark an import as lazy, Python
104+
defers the actual module loading until the imported name is first used. This
105+
gives you the organizational benefits of declaring all imports at the top of
106+
the file while only paying the loading cost for modules you actually use.
107107

108108
The ``lazy`` keyword works with both ``import`` and ``from ... import`` statements.
109109
When you write ``lazy import heavy_module``, Python does not immediately load the

Lib/test/.ruff.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extend-exclude = [
1313
# New grammar constructions may not yet be recognized by Ruff,
1414
# and tests re-use the same names as only the grammar is being checked.
1515
"test_grammar.py",
16-
# Lazy import syntax (PEP 810) not yet supported by Ruff
16+
# Lazy import syntax (PEP 810) is not yet supported by Ruff
1717
"test_import/data/lazy_imports/*.py",
1818
"test_import/data/lazy_imports/**/*.py",
1919
]

0 commit comments

Comments
 (0)