From d390ef3161aa21104b7def13612e00b6b3ef2d2e Mon Sep 17 00:00:00 2001 From: David Fisher Date: Fri, 11 Mar 2016 14:12:38 -0800 Subject: [PATCH] Make all function annotations accessible from builtins complete --- stdlib/2.7/__builtin__.pyi | 8 +++++--- stdlib/2.7/_weakrefset.pyi | 2 +- stdlib/2.7/abc.pyi | 14 +++++++------- stdlib/2.7/typing.pyi | 8 ++++---- stdlib/3/builtins.pyi | 10 ++++++---- stdlib/3/typing.pyi | 8 ++++---- 6 files changed, 27 insertions(+), 23 deletions(-) diff --git a/stdlib/2.7/__builtin__.pyi b/stdlib/2.7/__builtin__.pyi index 69a37feb9..d55d88ec6 100644 --- a/stdlib/2.7/__builtin__.pyi +++ b/stdlib/2.7/__builtin__.pyi @@ -49,7 +49,9 @@ class type: @overload def __init__(self, name: str, bases: Tuple[type, ...], dict: Dict[str, Any]) -> None: ... # TODO: __new__ may have to be special and not a static method. - @staticmethod + @overload + def __new__(cls, o: object) -> type: ... + @overload def __new__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> type: ... class int(SupportsInt, SupportsFloat, SupportsAbs[int]): @@ -401,7 +403,7 @@ class bytearray(Sequence[int]): def translate(self, table: str) -> bytearray: ... def upper(self) -> bytearray: ... def zfill(self, width: int) -> bytearray: ... - @staticmethod + @classmethod def fromhex(self, x: str) -> bytearray: ... def __len__(self) -> int: ... @@ -858,7 +860,7 @@ class file(BinaryIO): def __iter__(self) -> Iterator[str]: ... def read(self, n: int = ...) -> str: ... def __enter__(self) -> BinaryIO: ... - def __exit__(self, typ, exc, tb) -> bool: ... + def __exit__(self, t: type, exc: Any, tb: Any) -> bool: ... def flush(self) -> None: ... def fileno(self) -> int: ... def isatty(self) -> bool: ... diff --git a/stdlib/2.7/_weakrefset.pyi b/stdlib/2.7/_weakrefset.pyi index a3de693e6..d0689f16d 100644 --- a/stdlib/2.7/_weakrefset.pyi +++ b/stdlib/2.7/_weakrefset.pyi @@ -2,4 +2,4 @@ from typing import Iterator, Any class WeakSet: def __iter__(self) -> Iterator[Any]: ... - def add(self, *args, **kwargs) -> Any: ... + def add(self, *args: Any, **kwargs: Any) -> Any: ... diff --git a/stdlib/2.7/abc.pyi b/stdlib/2.7/abc.pyi index 66f7183b4..5e9abaa1d 100644 --- a/stdlib/2.7/abc.pyi +++ b/stdlib/2.7/abc.pyi @@ -1,4 +1,4 @@ -from typing import Any, Dict, Set, Union, Tuple +from typing import Any, Dict, Set, Union, Tuple, List import _weakrefset # mypy has special processing for ABCMeta and abstractmethod. @@ -7,7 +7,7 @@ WeakSet = ... # type: _weakrefset.WeakSet _InstanceType = ... # type: type types = ... # type: module -def abstractmethod(funcobj) -> Any: ... +def abstractmethod(funcobj: Any) -> Any: ... class ABCMeta(type): # TODO: FrozenSet @@ -18,10 +18,10 @@ class ABCMeta(type): _abc_negative_cache = ... # type: _weakrefset.WeakSet _abc_negative_cache_version = ... # type: int _abc_registry = ... # type: _weakrefset.WeakSet - def __init__(self, name, bases, namespace: Dict[Any, Any]) -> None: ... - def __instancecheck__(cls: "ABCMeta", instance) -> Any: ... - def __subclasscheck__(cls: "ABCMeta", subclass) -> Any: ... - def _dump_registry(cls: "ABCMeta", *args, **kwargs) -> None: ... + def __init__(self, name: str, bases: List[type], namespace: Dict[Any, Any]) -> None: ... + def __instancecheck__(cls: "ABCMeta", instance: Any) -> Any: ... + def __subclasscheck__(cls: "ABCMeta", subclass: Any) -> Any: ... + def _dump_registry(cls: "ABCMeta", *args: Any, **kwargs: Any) -> None: ... # TODO: subclass: Union["ABCMeta", type, Tuple[type, ...]] def register(cls: "ABCMeta", subclass: Any) -> None: ... @@ -30,7 +30,7 @@ class _C: # TODO: The real abc.abstractproperty inherits from "property". class abstractproperty(object): - def __new__(cls, func): ... + def __new__(cls, func: Any) -> Any: ... __doc__ = ... # type: str __isabstractmethod__ = ... # type: bool doc = ... # type: Any diff --git a/stdlib/2.7/typing.pyi b/stdlib/2.7/typing.pyi index a04ad24d5..b9384b917 100644 --- a/stdlib/2.7/typing.pyi +++ b/stdlib/2.7/typing.pyi @@ -20,8 +20,8 @@ NamedTuple = object() class TypeAlias: # Class for defining generic aliases for library types. - def __init__(self, target_type) -> None: ... - def __getitem__(self, typeargs): ... + def __init__(self, target_type: type) -> None: ... + def __getitem__(self, typeargs: Any) -> Any: ... Union = TypeAlias(object) Optional = TypeAlias(object) @@ -84,7 +84,7 @@ class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]): def send(self, value: _T_contra) -> _T_co:... @abstractmethod - def throw(self, typ: BaseException, val: Any=None, tb=None) -> None:... + def throw(self, typ: BaseException, val: Any = None, tb: Any = None) -> None:... @abstractmethod def close(self) -> None:... @@ -227,7 +227,7 @@ class IO(Iterable[AnyStr], Generic[AnyStr]): @abstractmethod def __enter__(self) -> 'IO[AnyStr]': ... @abstractmethod - def __exit__(self, type, value, traceback) -> bool: ... + def __exit__(self, t: type, value: Any, traceback: Any) -> bool: ... class BinaryIO(IO[str]): # TODO readinto diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index 505702f58..0eb1bc492 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -48,7 +48,9 @@ class type: def __init__(self, o: object) -> None: ... @overload def __init__(self, name: str, bases: Tuple[type, ...], dict: Dict[str, Any]) -> None: ... - @staticmethod + @overload + def __new__(cls, o: object) -> type: ... + @overload def __new__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> type: ... class int(SupportsInt, SupportsFloat, SupportsAbs[int]): @@ -224,10 +226,10 @@ class str(Sequence[str]): def zfill(self, width: int) -> str: ... @staticmethod @overload - def maketrans(self, x: Union[Dict[int, Any], Dict[str, Any]]) -> Dict[int, Any]: ... + def maketrans(x: Union[Dict[int, Any], Dict[str, Any]]) -> Dict[int, Any]: ... @staticmethod @overload - def maketrans(self, x: str, y: str, z: str = ...) -> Dict[int, Any]: ... + def maketrans(x: str, y: str, z: str = ...) -> Dict[int, Any]: ... def __getitem__(self, i: Union[int, slice]) -> str: ... def __add__(self, s: str) -> str: ... @@ -408,7 +410,7 @@ class bytearray(MutableSequence[int], ByteString): class memoryview(): # TODO arg can be any obj supporting the buffer protocol - def __init__(self, bytearray) -> None: ... + def __init__(self, b: bytearray) -> None: ... class bool(int, SupportsInt, SupportsFloat): def __init__(self, o: object = ...) -> None: ... diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index 1f31e8aa0..cf1c58286 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -21,8 +21,8 @@ no_type_check = object() class TypeAlias: # Class for defining generic aliases for library types. - def __init__(self, target_type) -> None: ... - def __getitem__(self, typeargs): ... + def __init__(self, target_type: type) -> None: ... + def __getitem__(self, typeargs: Any) -> Any: ... Union = TypeAlias(object) Optional = TypeAlias(object) @@ -102,7 +102,7 @@ class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]): def send(self, value: _T_contra) -> _T_co:... @abstractmethod - def throw(self, typ: BaseException, val: Any=None, tb=None) -> None:... + def throw(self, typ: BaseException, val: Any = None, tb: Any = None) -> None:... @abstractmethod def close(self) -> None:... @@ -284,7 +284,7 @@ class IO(Iterable[AnyStr], Generic[AnyStr]): @abstractmethod def __enter__(self) -> 'IO[AnyStr]': ... @abstractmethod - def __exit__(self, type, value, traceback) -> bool: ... + def __exit__(self, t: type, value: Any, traceback: Any) -> bool: ... class BinaryIO(IO[bytes]): # TODO readinto