From 13c83ed866f64b164270305aafb9081118ef333b Mon Sep 17 00:00:00 2001 From: layday Date: Fri, 19 Nov 2021 16:32:53 +0200 Subject: [PATCH 1/4] Remove `find_module` Deprecated since 3.4 and triggers spurious errors in type checkers when implementing a meta path finder without it. --- stdlib/sys.pyi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stdlib/sys.pyi b/stdlib/sys.pyi index 43d33ec62135..bfefeb89397c 100644 --- a/stdlib/sys.pyi +++ b/stdlib/sys.pyi @@ -1,6 +1,6 @@ import sys from builtins import object as _object -from importlib.abc import Loader, PathEntryFinder +from importlib.abc import PathEntryFinder from importlib.machinery import ModuleSpec from io import TextIOWrapper from types import FrameType, ModuleType, TracebackType @@ -31,7 +31,6 @@ _PathSequence = Sequence[Union[bytes, str]] # Unlike importlib.abc.MetaPathFinder, invalidate_caches() might not exist (see python docs) class _MetaPathFinder(Protocol): - def find_module(self, fullname: str, path: _PathSequence | None) -> Loader | None: ... def find_spec(self, fullname: str, path: _PathSequence | None, target: ModuleType | None = ...) -> ModuleSpec | None: ... # ----- sys variables ----- From f44295e8adb179e53e8ee0ecabf6c7b4314d1dd9 Mon Sep 17 00:00:00 2001 From: layday Date: Fri, 19 Nov 2021 16:39:41 +0200 Subject: [PATCH 2/4] Align `find_spec` signature with `ModuleType` --- stdlib/sys.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/sys.pyi b/stdlib/sys.pyi index bfefeb89397c..7be5adc58ef1 100644 --- a/stdlib/sys.pyi +++ b/stdlib/sys.pyi @@ -27,11 +27,11 @@ _T = TypeVar("_T") # The following type alias are stub-only and do not exist during runtime _ExcInfo = Tuple[Type[BaseException], BaseException, TracebackType] _OptExcInfo = Union[_ExcInfo, Tuple[None, None, None]] -_PathSequence = Sequence[Union[bytes, str]] +_ModulePath = Sequence[str] # Unlike importlib.abc.MetaPathFinder, invalidate_caches() might not exist (see python docs) class _MetaPathFinder(Protocol): - def find_spec(self, fullname: str, path: _PathSequence | None, target: ModuleType | None = ...) -> ModuleSpec | None: ... + def find_spec(self, fullname: str, path: _ModulePath | None, target: ModuleType | None = ...) -> ModuleSpec | None: ... # ----- sys variables ----- if sys.platform != "win32": From 590b8df7c0fc8b0a1a3374fe74ab7dd62f4a42f5 Mon Sep 17 00:00:00 2001 From: layday Date: Fri, 19 Nov 2021 21:54:15 +0200 Subject: [PATCH 3/4] Inline type alias --- stdlib/sys.pyi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stdlib/sys.pyi b/stdlib/sys.pyi index 7be5adc58ef1..15ab328c3777 100644 --- a/stdlib/sys.pyi +++ b/stdlib/sys.pyi @@ -27,11 +27,10 @@ _T = TypeVar("_T") # The following type alias are stub-only and do not exist during runtime _ExcInfo = Tuple[Type[BaseException], BaseException, TracebackType] _OptExcInfo = Union[_ExcInfo, Tuple[None, None, None]] -_ModulePath = Sequence[str] # Unlike importlib.abc.MetaPathFinder, invalidate_caches() might not exist (see python docs) class _MetaPathFinder(Protocol): - def find_spec(self, fullname: str, path: _ModulePath | None, target: ModuleType | None = ...) -> ModuleSpec | None: ... + def find_spec(self, fullname: str, path: Sequence[str] | None, target: ModuleType | None = ...) -> ModuleSpec | None: ... # ----- sys variables ----- if sys.platform != "win32": From 98904b66e29be2879ecdd05e868f32e26e9a0480 Mon Sep 17 00:00:00 2001 From: layday Date: Sat, 20 Nov 2021 13:08:10 +0200 Subject: [PATCH 4/4] Update comment above `_MetaPathFinder` --- stdlib/sys.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/sys.pyi b/stdlib/sys.pyi index 15ab328c3777..5c411d04e75f 100644 --- a/stdlib/sys.pyi +++ b/stdlib/sys.pyi @@ -28,7 +28,7 @@ _T = TypeVar("_T") _ExcInfo = Tuple[Type[BaseException], BaseException, TracebackType] _OptExcInfo = Union[_ExcInfo, Tuple[None, None, None]] -# Unlike importlib.abc.MetaPathFinder, invalidate_caches() might not exist (see python docs) +# Intentionally omits one deprecated and one optional method of `importlib.abc.MetaPathFinder` class _MetaPathFinder(Protocol): def find_spec(self, fullname: str, path: Sequence[str] | None, target: ModuleType | None = ...) -> ModuleSpec | None: ...