File tree Expand file tree Collapse file tree 3 files changed +8
-7
lines changed
Expand file tree Collapse file tree 3 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -905,8 +905,9 @@ names remain as lazy proxies until they are accessed.
905905Example::
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"})
Original file line number Diff line number Diff line change @@ -99,11 +99,11 @@ unnecessary dependencies. These approaches work but make code harder to read
9999and maintain, scatter import statements throughout the codebase, and require
100100discipline 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
108108The ``lazy `` keyword works with both ``import `` and ``from ... import `` statements.
109109When you write ``lazy import heavy_module ``, Python does not immediately load the
Original file line number Diff line number Diff 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]
You can’t perform that action at this time.
0 commit comments