From 127444594111d86ce48de2fd8cf6d9ac613da471 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 16 Nov 2021 14:19:21 +0000 Subject: [PATCH] Resolve builtins/importlib inconsistencies (#6310) --- stdlib/builtins.pyi | 1 + stdlib/importlib/__init__.pyi | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 4ccaf52d4..54bea2276 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -1443,6 +1443,7 @@ class zip(Iterator[_T_co], Generic[_T_co]): def __iter__(self) -> Iterator[_T_co]: ... def __next__(self) -> _T_co: ... +# Signature of `builtins.__import__` should be kept identical to `importlib.__import__` # Return type of `__import__` should be kept the same as return type of `importlib.import_module` def __import__( name: str, diff --git a/stdlib/importlib/__init__.pyi b/stdlib/importlib/__init__.pyi index af7c3f500..1b91cc55f 100644 --- a/stdlib/importlib/__init__.pyi +++ b/stdlib/importlib/__init__.pyi @@ -1,16 +1,18 @@ -import types from importlib.abc import Loader -from typing import Any, Mapping, Sequence +from types import ModuleType +from typing import Mapping, Sequence -# `__import__` and `import_module` return type should be kept the same as `builtins.__import__` +# Signature of `builtins.__import__` should be kept identical to `importlib.__import__` def __import__( name: str, - globals: Mapping[str, Any] | None = ..., - locals: Mapping[str, Any] | None = ..., + globals: Mapping[str, object] | None = ..., + locals: Mapping[str, object] | None = ..., fromlist: Sequence[str] = ..., level: int = ..., -) -> types.ModuleType: ... -def import_module(name: str, package: str | None = ...) -> types.ModuleType: ... +) -> ModuleType: ... + +# `importlib.import_module` return type should be kept the same as `builtins.__import__` +def import_module(name: str, package: str | None = ...) -> ModuleType: ... def find_loader(name: str, path: str | None = ...) -> Loader | None: ... def invalidate_caches() -> None: ... -def reload(module: types.ModuleType) -> types.ModuleType: ... +def reload(module: ModuleType) -> ModuleType: ...