Skip to content

Commit 23c08dc

Browse files
Carreauclaude
andcommitted
Remove LoaderProtocol.load_module on Python 3.15+
importlib.abc.Loader.load_module was removed in Python 3.15, and importlib/_abc.pyi already gates it with `sys.version_info < (3, 15)` (done in #16285). That change did not touch `_typeshed/importlib.pyi`, so LoaderProtocol still required `load_module` unconditionally. On 3.15 a plain `importlib.abc.Loader` subclass is therefore rejected by importlib.util.spec_from_loader, importlib.machinery.ModuleSpec, and other users of the protocol: error: Argument 2 to "spec_from_loader" has incompatible type "MyLoader"; expected "LoaderProtocol | None" Gate `load_module` the same way. The comment at the top of importlib.pyi say that deprecated and optinal method, technically I suppose load_module has been deprecated since 3.10, so the verision gate could be 3.10+ ? Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 9741952 commit 23c08dc

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎stdlib/_typeshed/importlib.pyi‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Implicit protocols used in importlib.
22
# We intentionally omit deprecated and optional methods.
33

4+
import sys
45
from collections.abc import Sequence
56
from importlib.machinery import ModuleSpec
67
from types import ModuleType
@@ -9,7 +10,8 @@ from typing import Protocol
910
__all__ = ["LoaderProtocol", "MetaPathFinderProtocol", "PathEntryFinderProtocol"]
1011

1112
class LoaderProtocol(Protocol):
12-
def load_module(self, fullname: str, /) -> ModuleType: ...
13+
if sys.version_info < (3, 15):
14+
def load_module(self, fullname: str, /) -> ModuleType: ...
1315

1416
class MetaPathFinderProtocol(Protocol):
1517
def find_spec(self, fullname: str, path: Sequence[str] | None, target: ModuleType | None = ..., /) -> ModuleSpec | None: ...

0 commit comments

Comments
 (0)