Skip to content

Commit e86de6b

Browse files
committed
gh-148588: Add relative import example to __lazy_modules__ docs
1 parent 2005434 commit e86de6b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Doc/reference/simple_stmts.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,13 @@ Python versions older than 3.15 while leveraging lazy imports on 3.15+::
948948
import pathlib # loaded lazily
949949

950950
Relative imports are resolved to their absolute name before the lookup, so
951-
the sequence must always contain fully qualified module names.
951+
the sequence must always contain fully qualified module names::
952+
953+
# In mypackage/mymodule.py
954+
__lazy_modules__ = ["mypackage"]
955+
956+
from . import utils # loaded lazily: resolves to mypackage
957+
import json # loaded eagerly (not in __lazy_modules__)
952958

953959
Imports inside functions, class bodies, or
954960
:keyword:`try`/:keyword:`except`/:keyword:`finally` blocks are always eager,

0 commit comments

Comments
 (0)