Harmonise return type of builtins.__import__ and importlib.import_module (#6302)

builtins.__import__ now returns ModuleType instead of Any. In addition, add __getattr__() to ModuleType to ease using imported modules.
This commit is contained in:
Alex Waygood
2021-11-15 15:21:46 +00:00
committed by GitHub
parent 10c9d8cfce
commit aa7e277adb
4 changed files with 8 additions and 1 deletions

View File

@@ -178,6 +178,10 @@ class ModuleType:
__path__: MutableSequence[str]
__spec__: ModuleSpec | None
def __init__(self, name: str, doc: str | None = ...) -> None: ...
# __getattr__ doesn't exist at runtime,
# but having it here in typeshed makes dynamic imports
# using `builtins.__import__` or `importlib.import_module` less painful
def __getattr__(self, name: str) -> Any: ...
@final
class GeneratorType(Generator[_T_co, _T_contra, _V_co]):