From 0ee7c3c38b05a4d1712353bda5e6cffdaab2438b Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Fri, 16 Aug 2019 02:03:00 -0700 Subject: [PATCH] Update __import__ function annotations (#3188) Per the docs, globals/locals is an optional argument. Additionally, globals/locals can be any mapping type, not only a dict. Likewise, fromlist can be any sequence (the docs mention a tuple, not a list). The function returns a ModuleType, not Any. --- stdlib/2/__builtin__.pyi | 8 +++++--- stdlib/2and3/builtins.pyi | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index bf12fc093..37d72736e 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -11,7 +11,7 @@ from typing import ( ) from abc import abstractmethod, ABCMeta from ast import mod, AST -from types import TracebackType, CodeType +from types import TracebackType, CodeType, ModuleType import sys if sys.version_info >= (3,): @@ -1437,8 +1437,10 @@ else: def zip(__iter1: Iterable[Any], __iter2: Iterable[Any], __iter3: Iterable[Any], __iter4: Iterable[Any], __iter5: Iterable[Any], __iter6: Iterable[Any], *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... -def __import__(name: Text, globals: Dict[str, Any] = ..., locals: Dict[str, Any] = ..., - fromlist: List[str] = ..., level: int = ...) -> Any: ... +def __import__(name: Text, globals: Optional[Mapping[str, Any]] = ..., + locals: Optional[Mapping[str, Any]] = ..., + fromlist: Sequence[str] = ..., + level: int = ...) -> ModuleType: ... # Actually the type of Ellipsis is , but since it's # not exposed anywhere under that name, we make it private here. diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index bf12fc093..37d72736e 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -11,7 +11,7 @@ from typing import ( ) from abc import abstractmethod, ABCMeta from ast import mod, AST -from types import TracebackType, CodeType +from types import TracebackType, CodeType, ModuleType import sys if sys.version_info >= (3,): @@ -1437,8 +1437,10 @@ else: def zip(__iter1: Iterable[Any], __iter2: Iterable[Any], __iter3: Iterable[Any], __iter4: Iterable[Any], __iter5: Iterable[Any], __iter6: Iterable[Any], *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... -def __import__(name: Text, globals: Dict[str, Any] = ..., locals: Dict[str, Any] = ..., - fromlist: List[str] = ..., level: int = ...) -> Any: ... +def __import__(name: Text, globals: Optional[Mapping[str, Any]] = ..., + locals: Optional[Mapping[str, Any]] = ..., + fromlist: Sequence[str] = ..., + level: int = ...) -> ModuleType: ... # Actually the type of Ellipsis is , but since it's # not exposed anywhere under that name, we make it private here.