Skip to content

Commit f24d587

Browse files
committed
gh-148588: Clarify __lazy_modules__ must be a container (__contains__), not any iterable
1 parent e9c0d3b commit f24d587

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

Doc/reference/datamodel.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,8 @@ the following writable attributes:
11241124

11251125
.. attribute:: module.__lazy_modules__
11261126

1127-
A container of fully qualified module name strings. When defined
1127+
A container (an object implementing :meth:`~object.__contains__`) of fully
1128+
qualified module name strings. When defined
11281129
at module scope, any regular :keyword:`import` statement in that module whose
11291130
target module name appears in this container is treated as a
11301131
:ref:`lazy import <lazy-imports>`, as if the :keyword:`lazy` keyword had

Doc/reference/simple_stmts.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,8 @@ Compatibility mode via ``__lazy_modules__``
931931
As an alternative to using the :keyword:`lazy` keyword, a module can opt
932932
into lazy loading for specific imports by defining a module-level
933933
:attr:`~module.__lazy_modules__` variable. When present, it must be a
934-
container of fully qualified module name strings. Any regular (non-``lazy``)
934+
container (an object implementing :meth:`~object.__contains__`) of fully
935+
qualified module name strings. Any regular (non-``lazy``)
935936
:keyword:`import` statement at module scope whose target appears in
936937
:attr:`!__lazy_modules__` is treated as a lazy import, exactly as if the
937938
:keyword:`lazy` keyword had been used.

Doc/whatsnew/3.15.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ raise :exc:`SyntaxError`).
185185
For code that cannot use the ``lazy`` keyword directly (for example, when
186186
supporting Python versions older than 3.15 while still leveraging lazy
187187
imports on 3.15+), a module can define
188-
:attr:`~module.__lazy_modules__` as an :term:`iterable` of fully qualified module
189-
name strings. Regular ``import`` statements for those modules are then treated
188+
:attr:`~module.__lazy_modules__` as a container (an object implementing
189+
:meth:`~object.__contains__`) of fully qualified module name strings. Regular ``import`` statements for those modules are then treated
190190
as lazy, with the same semantics as the ``lazy`` keyword::
191191

192192
__lazy_modules__ = ["json", "pathlib"]

0 commit comments

Comments
 (0)