diff --git a/stdlib/2/ConfigParser.pyi b/stdlib/2/ConfigParser.pyi index 5d86811726a8..fa0e551717d1 100644 --- a/stdlib/2/ConfigParser.pyi +++ b/stdlib/2/ConfigParser.pyi @@ -55,8 +55,8 @@ class _Readable(Protocol): class RawConfigParser: _dict: Any - _sections: dict - _defaults: dict + _sections: Dict[Any, Any] + _defaults: Dict[Any, Any] _optcre: Any SECTCRE: Any OPTCRE: Any @@ -86,12 +86,14 @@ class RawConfigParser: class ConfigParser(RawConfigParser): _KEYCRE: Any - def get(self, section: str, option: str, raw: bool = ..., vars: Optional[dict] = ...) -> Any: ... - def items(self, section: str, raw: bool = ..., vars: Optional[dict] = ...) -> List[Tuple[str, Any]]: ... + def get(self, section: str, option: str, raw: bool = ..., vars: Optional[Dict[Any, Any]] = ...) -> Any: ... + def items(self, section: str, raw: bool = ..., vars: Optional[Dict[Any, Any]] = ...) -> List[Tuple[str, Any]]: ... def _interpolate(self, section: str, option: str, rawval: Any, vars: Any) -> str: ... def _interpolation_replace(self, match: Any) -> str: ... class SafeConfigParser(ConfigParser): _interpvar_re: Any def _interpolate(self, section: str, option: str, rawval: Any, vars: Any) -> str: ... - def _interpolate_some(self, option: str, accum: list, rest: str, section: str, map: dict, depth: int) -> None: ... + def _interpolate_some( + self, option: str, accum: List[Any], rest: str, section: str, map: Dict[Any, Any], depth: int, + ) -> None: ... diff --git a/stdlib/2/Cookie.pyi b/stdlib/2/Cookie.pyi index 79a7a8141ef6..91dd93221c73 100644 --- a/stdlib/2/Cookie.pyi +++ b/stdlib/2/Cookie.pyi @@ -1,8 +1,8 @@ -from typing import Any, Optional +from typing import Any, Dict, Optional class CookieError(Exception): ... -class Morsel(dict): +class Morsel(Dict[Any, Any]): key: Any def __init__(self): ... def __setitem__(self, K, V): ... @@ -14,7 +14,7 @@ class Morsel(dict): def js_output(self, attrs: Optional[Any] = ...): ... def OutputString(self, attrs: Optional[Any] = ...): ... -class BaseCookie(dict): +class BaseCookie(Dict[Any, Any]): def value_decode(self, val): ... def value_encode(self, val): ... def __init__(self, input: Optional[Any] = ...): ... diff --git a/stdlib/2/Queue.pyi b/stdlib/2/Queue.pyi index 1593eb1c6a67..76e3dcb5024f 100644 --- a/stdlib/2/Queue.pyi +++ b/stdlib/2/Queue.pyi @@ -1,7 +1,7 @@ # Stubs for Queue (Python 2) from collections import deque -from typing import Any, TypeVar, Generic, Optional +from typing import Any, Deque, TypeVar, Generic, Optional _T = TypeVar('_T') @@ -15,7 +15,7 @@ class Queue(Generic[_T]): not_full: Any all_tasks_done: Any unfinished_tasks: Any - queue: deque # undocumented + queue: Deque[Any] # undocumented def __init__(self, maxsize: int = ...) -> None: ... def task_done(self) -> None: ... def join(self) -> None: ... diff --git a/stdlib/2/SimpleHTTPServer.pyi b/stdlib/2/SimpleHTTPServer.pyi index be22b88381d7..4a36cc5bdfe4 100644 --- a/stdlib/2/SimpleHTTPServer.pyi +++ b/stdlib/2/SimpleHTTPServer.pyi @@ -9,7 +9,7 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(self) -> None: ... def do_HEAD(self) -> None: ... def send_head(self) -> Optional[IO[str]]: ... - def list_directory(self, path: Union[str, unicode]) -> Optional[StringIO]: ... + def list_directory(self, path: Union[str, unicode]) -> Optional[StringIO[Any]]: ... def translate_path(self, path: AnyStr) -> AnyStr: ... def copyfile(self, source: IO[AnyStr], outputfile: IO[AnyStr]): ... def guess_type(self, path: Union[str, unicode]) -> str: ... diff --git a/stdlib/2/UserList.pyi b/stdlib/2/UserList.pyi index b8466eed1405..97ba17a9b513 100644 --- a/stdlib/2/UserList.pyi +++ b/stdlib/2/UserList.pyi @@ -1,7 +1,7 @@ from typing import Iterable, MutableSequence, TypeVar, Union, overload _T = TypeVar("_T") -_ULT = TypeVar("_ULT", bound=UserList) +_S = TypeVar("_S") class UserList(MutableSequence[_T]): def insert(self, index: int, object: _T) -> None: ... @@ -14,5 +14,5 @@ class UserList(MutableSequence[_T]): @overload def __getitem__(self, i: int) -> _T: ... @overload - def __getitem__(self: _ULT, s: slice) -> _ULT: ... + def __getitem__(self: _S, s: slice) -> _S: ... def sort(self) -> None: ... diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 9b4c83dc8949..62052cfb7186 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -870,7 +870,7 @@ class tuple(Sequence[_T_co], Generic[_T_co]): @overload def __add__(self, x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ... @overload - def __add__(self, x: tuple) -> tuple: ... + def __add__(self, x: Tuple[Any, ...]) -> Tuple[Any, ...]: ... def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ... def count(self, x: Any) -> int: ... diff --git a/stdlib/2/_collections.pyi b/stdlib/2/_collections.pyi index e24d4053b233..9736a49b9366 100644 --- a/stdlib/2/_collections.pyi +++ b/stdlib/2/_collections.pyi @@ -1,18 +1,19 @@ """Stub file for the '_collections' module.""" -from typing import Any, Generic, Iterator, TypeVar, Optional, Union - -class defaultdict(dict): - default_factory: None - def __init__(self, default: Any = ..., init: Any = ...) -> None: ... - def __missing__(self, key) -> Any: - raise KeyError() - def __copy__(self) -> defaultdict: ... - def copy(self) -> defaultdict: ... +from typing import Any, Callable, Dict, Generic, Iterator, TypeVar, Optional, Union +_K = TypeVar("_K") +_V = TypeVar("_V") _T = TypeVar('_T') _T2 = TypeVar('_T2') +class defaultdict(Dict[_K, _V]): + default_factory: None + def __init__(self, __default_factory: Callable[[], _V] = ..., init: Any = ...) -> None: ... + def __missing__(self, key: _K) -> _V: ... + def __copy__(self: _T) -> _T: ... + def copy(self: _T) -> _T: ... + class deque(Generic[_T]): maxlen: Optional[int] def __init__(self, iterable: Iterator[_T] = ..., maxlen: int = ...) -> None: ... diff --git a/stdlib/2/_hotshot.pyi b/stdlib/2/_hotshot.pyi index 8a9c8d72bdfd..f75acf24323a 100644 --- a/stdlib/2/_hotshot.pyi +++ b/stdlib/2/_hotshot.pyi @@ -14,7 +14,7 @@ def logreader(a: str) -> LogReaderType: def profiler(a: str, *args, **kwargs) -> Any: raise IOError() -def resolution() -> tuple: ... +def resolution() -> Tuple[Any, ...]: ... class LogReaderType(object): diff --git a/stdlib/2/_io.pyi b/stdlib/2/_io.pyi index dd4d1440dd13..d0185ae7da0c 100644 --- a/stdlib/2/_io.pyi +++ b/stdlib/2/_io.pyi @@ -84,8 +84,8 @@ class BufferedWriter(_BufferedIOBase): class BytesIO(_BufferedIOBase): def __init__(self, initial_bytes: bytes = ...) -> None: ... - def __setstate__(self, tuple) -> None: ... - def __getstate__(self) -> tuple: ... + def __setstate__(self, state: Tuple[Any, ...]) -> None: ... + def __getstate__(self) -> Tuple[Any, ...]: ... # BytesIO does not contain a "name" field. This workaround is necessary # to allow BytesIO sub-classes to add this field, as it is defined # as a read-only property on IO[]. @@ -129,7 +129,7 @@ class _TextIOBase(TextIO): def _checkSeekable(self) -> None: ... def _checkWritable(self) -> None: ... def close(self) -> None: ... - def detach(self) -> IO: ... + def detach(self) -> IO[Any]: ... def fileno(self) -> int: ... def flush(self) -> None: ... def isatty(self) -> bool: ... @@ -154,8 +154,8 @@ class StringIO(_TextIOBase): def __init__(self, initial_value: Optional[unicode] = ..., newline: Optional[unicode] = ...) -> None: ... - def __setstate__(self, state: tuple) -> None: ... - def __getstate__(self) -> tuple: ... + def __setstate__(self, state: Tuple[Any, ...]) -> None: ... + def __getstate__(self) -> Tuple[Any, ...]: ... # StringIO does not contain a "name" field. This workaround is necessary # to allow StringIO sub-classes to add this field, as it is defined # as a read-only property on IO[]. @@ -167,12 +167,15 @@ class TextIOWrapper(_TextIOBase): line_buffering: bool buffer: BinaryIO _CHUNK_SIZE: int - def __init__(self, buffer: IO, - encoding: Optional[Text] = ..., - errors: Optional[Text] = ..., - newline: Optional[Text] = ..., - line_buffering: bool = ..., - write_through: bool = ...) -> None: ... + def __init__( + self, + buffer: IO[Any], + encoding: Optional[Text] = ..., + errors: Optional[Text] = ..., + newline: Optional[Text] = ..., + line_buffering: bool = ..., + write_through: bool = ..., + ) -> None: ... def open(file: Union[str, unicode, int], mode: Text = ..., diff --git a/stdlib/2/_json.pyi b/stdlib/2/_json.pyi index 028b7b229a89..f8bd265aca13 100644 --- a/stdlib/2/_json.pyi +++ b/stdlib/2/_json.pyi @@ -1,17 +1,7 @@ -"""Stub file for the '_json' module.""" -# This is an autogenerated file. It serves as a starting point -# for a more precise manual annotation of this module. -# Feel free to edit the source below, but remove this header when you do. - -from typing import Any, List, Tuple, Dict, Generic - -def encode_basestring_ascii(*args, **kwargs) -> str: - raise TypeError() - -def scanstring(a, b, *args, **kwargs) -> tuple: - raise TypeError() +from typing import Any, List, Tuple, Dict, Generic, Tuple +def encode_basestring_ascii(*args, **kwargs) -> str: ... +def scanstring(a, b, *args, **kwargs) -> Tuple[Any, ...]: ... class Encoder(object): ... - class Scanner(object): ... diff --git a/stdlib/2/_socket.pyi b/stdlib/2/_socket.pyi index 8d02bdee3f16..31ba7638afc6 100644 --- a/stdlib/2/_socket.pyi +++ b/stdlib/2/_socket.pyi @@ -253,17 +253,17 @@ class SocketType(object): timeout: float def __init__(self, family: int = ..., type: int = ..., proto: int = ...) -> None: ... - def accept(self) -> Tuple[SocketType, tuple]: ... - def bind(self, address: tuple) -> None: ... + def accept(self) -> Tuple[SocketType, Tuple[Any, ...]]: ... + def bind(self, address: Tuple[Any, ...]) -> None: ... def close(self) -> None: ... - def connect(self, address: tuple) -> None: + def connect(self, address: Tuple[Any, ...]) -> None: raise gaierror raise timeout - def connect_ex(self, address: tuple) -> int: ... + def connect_ex(self, address: Tuple[Any, ...]) -> int: ... def dup(self) -> SocketType: ... def fileno(self) -> int: ... - def getpeername(self) -> tuple: ... - def getsockname(self) -> tuple: ... + def getpeername(self) -> Tuple[Any, ...]: ... + def getsockname(self) -> Tuple[Any, ...]: ... def getsockopt(self, level: int, option: int, buffersize: int = ...) -> str: ... def gettimeout(self) -> float: ... def listen(self, backlog: int) -> None: @@ -271,16 +271,16 @@ class SocketType(object): def makefile(self, mode: str = ..., buffersize: int = ...) -> IO[Any]: ... def recv(self, buffersize: int, flags: int = ...) -> str: ... def recv_into(self, buffer: bytearray, nbytes: int = ..., flags: int = ...) -> int: ... - def recvfrom(self, buffersize: int, flags: int = ...) -> tuple: + def recvfrom(self, buffersize: int, flags: int = ...) -> Tuple[Any, ...]: raise error def recvfrom_into(self, buffer: bytearray, nbytes: int = ..., flags: int = ...) -> int: ... def send(self, data: str, flags: int = ...) -> int: ... def sendall(self, data: str, flags: int = ...) -> None: ... @overload - def sendto(self, data: str, address: tuple) -> int: ... + def sendto(self, data: str, address: Tuple[Any, ...]) -> int: ... @overload - def sendto(self, data: str, flags: int, address: tuple) -> int: ... + def sendto(self, data: str, flags: int, address: Tuple[Any, ...]) -> int: ... def setblocking(self, flag: bool) -> None: ... def setsockopt(self, level: int, option: int, value: Union[int, str]) -> None: ... def settimeout(self, value: Optional[float]) -> None: ... diff --git a/stdlib/2/_sre.pyi b/stdlib/2/_sre.pyi index 9b327d1c91d7..5ab7ed124da4 100644 --- a/stdlib/2/_sre.pyi +++ b/stdlib/2/_sre.pyi @@ -35,14 +35,14 @@ class SRE_Pattern(object): groups: int groupindex: Mapping[str, int] indexgroup: Sequence[int] - def findall(self, source: str, pos: int = ..., endpos: int = ...) -> List[Union[tuple, str]]: ... - def finditer(self, source: str, pos: int = ..., endpos: int = ...) -> Iterable[Union[tuple, str]]: ... + def findall(self, source: str, pos: int = ..., endpos: int = ...) -> List[Union[Tuple[Any, ...], str]]: ... + def finditer(self, source: str, pos: int = ..., endpos: int = ...) -> Iterable[Union[Tuple[Any, ...], str]]: ... def match(self, pattern, pos: int = ..., endpos: int = ...) -> SRE_Match: ... def scanner(self, s: str, start: int = ..., end: int = ...) -> SRE_Scanner: ... def search(self, pattern, pos: int = ..., endpos: int = ...) -> SRE_Match: ... def split(self, source: str, maxsplit: int = ...) -> List[Optional[str]]: ... - def sub(self, repl: str, string: str, count: int = ...) -> tuple: ... - def subn(self, repl: str, string: str, count: int = ...) -> tuple: ... + def sub(self, repl: str, string: str, count: int = ...) -> Tuple[Any, ...]: ... + def subn(self, repl: str, string: str, count: int = ...) -> Tuple[Any, ...]: ... def compile(pattern: str, flags: int, code: List[int], groups: int = ..., diff --git a/stdlib/2/_warnings.pyi b/stdlib/2/_warnings.pyi index 9609faa4ec1d..192fbd21355a 100644 --- a/stdlib/2/_warnings.pyi +++ b/stdlib/2/_warnings.pyi @@ -1,11 +1,16 @@ -from typing import Any, List, Optional, Type +from typing import Any, Dict, List, Optional, Tuple, Type default_action: str -filters: List[tuple] -once_registry: dict +filters: List[Tuple[Any, ...]] +once_registry: Dict[Any, Any] def warn(message: Warning, category: Optional[Type[Warning]] = ..., stacklevel: int = ...) -> None: ... -def warn_explicit(message: Warning, category: Optional[Type[Warning]], - filename: str, lineno: int, - module: Any = ..., registry: dict = ..., - module_globals: dict = ...) -> None: ... +def warn_explicit( + message: Warning, + category: Optional[Type[Warning]], + filename: str, + lineno: int, + module: Any = ..., + registry: Dict[Any, Any] = ..., + module_globals: Dict[Any, Any] = ..., +) -> None: ... diff --git a/stdlib/2/abc.pyi b/stdlib/2/abc.pyi index e5fe035f2cba..64fbb50bc706 100644 --- a/stdlib/2/abc.pyi +++ b/stdlib/2/abc.pyi @@ -10,11 +10,11 @@ def abstractmethod(funcobj: _FuncT) -> _FuncT: ... class ABCMeta(type): # TODO: FrozenSet __abstractmethods__: Set[Any] - _abc_cache: _weakrefset.WeakSet + _abc_cache: _weakrefset.WeakSet[Any] _abc_invalidation_counter: int - _abc_negative_cache: _weakrefset.WeakSet + _abc_negative_cache: _weakrefset.WeakSet[Any] _abc_negative_cache_version: int - _abc_registry: _weakrefset.WeakSet + _abc_registry: _weakrefset.WeakSet[Any] def __init__(self, name: str, bases: Tuple[type, ...], namespace: Dict[Any, Any]) -> None: ... def __instancecheck__(cls: ABCMeta, instance: Any) -> Any: ... def __subclasscheck__(cls: ABCMeta, subclass: Any) -> Any: ... diff --git a/stdlib/2/collections.pyi b/stdlib/2/collections.pyi index 0daa118e53a7..988e9202f674 100644 --- a/stdlib/2/collections.pyi +++ b/stdlib/2/collections.pyi @@ -1,5 +1,5 @@ # These are not exported. -from typing import Dict, Generic, TypeVar, Tuple, overload, Type, Optional, List, Union, Reversible +from typing import Any, Dict, Generic, TypeVar, Tuple, overload, Type, Optional, List, Union, Reversible # These are exported. from typing import ( @@ -28,7 +28,7 @@ _VT = TypeVar('_VT') # namedtuple is special-cased in the type checker; the initializer is ignored. def namedtuple(typename: Union[str, unicode], field_names: Union[str, unicode, Iterable[Union[str, unicode]]], - verbose: bool = ..., rename: bool = ...) -> Type[tuple]: ... + verbose: bool = ..., rename: bool = ...) -> Type[Tuple[Any, ...]]: ... class deque(Sized, Iterable[_T], Reversible[_T], Generic[_T]): def __init__(self, iterable: Iterable[_T] = ..., @@ -56,8 +56,6 @@ class deque(Sized, Iterable[_T], Reversible[_T], Generic[_T]): def __reversed__(self) -> Iterator[_T]: ... def __iadd__(self: _S, iterable: Iterable[_T]) -> _S: ... -_CounterT = TypeVar('_CounterT', bound=Counter) - class Counter(Dict[_T, int], Generic[_T]): @overload def __init__(self, **kwargs: int) -> None: ... @@ -65,7 +63,7 @@ class Counter(Dict[_T, int], Generic[_T]): def __init__(self, mapping: Mapping[_T, int]) -> None: ... @overload def __init__(self, iterable: Iterable[_T]) -> None: ... - def copy(self: _CounterT) -> _CounterT: ... + def copy(self: _S) -> _S: ... def elements(self) -> Iterator[_T]: ... def most_common(self, n: Optional[int] = ...) -> List[Tuple[_T, int]]: ... @overload @@ -93,15 +91,11 @@ class Counter(Dict[_T, int], Generic[_T]): def __iand__(self, other: Counter[_T]) -> Counter[_T]: ... def __ior__(self, other: Counter[_T]) -> Counter[_T]: ... -_OrderedDictT = TypeVar('_OrderedDictT', bound=OrderedDict) - class OrderedDict(Dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]): def popitem(self, last: bool = ...) -> Tuple[_KT, _VT]: ... - def copy(self: _OrderedDictT) -> _OrderedDictT: ... + def copy(self: _S) -> _S: ... def __reversed__(self) -> Iterator[_KT]: ... -_DefaultDictT = TypeVar('_DefaultDictT', bound=defaultdict) - class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]): default_factory: Callable[[], _VT] @overload @@ -123,4 +117,4 @@ class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]): def __init__(self, default_factory: Optional[Callable[[], _VT]], iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... def __missing__(self, key: _KT) -> _VT: ... - def copy(self: _DefaultDictT) -> _DefaultDictT: ... + def copy(self: _S) -> _S: ... diff --git a/stdlib/2/compileall.pyi b/stdlib/2/compileall.pyi index c3e861e1e99d..2b7046d8260c 100644 --- a/stdlib/2/compileall.pyi +++ b/stdlib/2/compileall.pyi @@ -1,10 +1,19 @@ # Stubs for compileall (Python 2) -from typing import Optional, Pattern, Union +from typing import Any, Optional, Pattern, Union _Path = Union[str, bytes] # rx can be any object with a 'search' method; once we have Protocols we can change the type -def compile_dir(dir: _Path, maxlevels: int = ..., ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern] = ..., quiet: int = ...) -> int: ... -def compile_file(fullname: _Path, ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern] = ..., quiet: int = ...) -> int: ... +def compile_dir( + dir: _Path, + maxlevels: int = ..., + ddir: Optional[_Path] = ..., + force: bool = ..., + rx: Optional[Pattern[Any]] = ..., + quiet: int = ..., +) -> int: ... +def compile_file( + fullname: _Path, ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern[Any]] = ..., quiet: int = ..., +) -> int: ... def compile_path(skip_curdir: bool = ..., maxlevels: int = ..., force: bool = ..., quiet: int = ...) -> int: ... diff --git a/stdlib/2/email/iterators.pyi b/stdlib/2/email/iterators.pyi index 48aaf06a6f67..5002644117a4 100644 --- a/stdlib/2/email/iterators.pyi +++ b/stdlib/2/email/iterators.pyi @@ -1,5 +1,5 @@ -from typing import Generator +from typing import Any, Generator -def walk(self) -> Generator: ... -def body_line_iterator(msg, decode: bool = ...) -> Generator: ... -def typed_subpart_iterator(msg, maintype=..., subtype=...) -> Generator: ... +def walk(self) -> Generator[Any, Any, Any]: ... +def body_line_iterator(msg, decode: bool = ...) -> Generator[Any, Any, Any]: ... +def typed_subpart_iterator(msg, maintype=..., subtype=...) -> Generator[Any, Any, Any]: ... diff --git a/stdlib/2/email/message.pyi b/stdlib/2/email/message.pyi index bd3c6220d6e1..642bba7c0102 100644 --- a/stdlib/2/email/message.pyi +++ b/stdlib/2/email/message.pyi @@ -1,4 +1,4 @@ -from typing import Generator +from typing import Any, Generator class Message: preamble = ... @@ -42,4 +42,4 @@ class Message: def set_boundary(self, boundary) -> None: ... def get_content_charset(self, failobj=...): ... def get_charsets(self, failobj=...): ... - def walk(self) -> Generator: ... + def walk(self) -> Generator[Any, Any, Any]: ... diff --git a/stdlib/2/inspect.pyi b/stdlib/2/inspect.pyi index 4e157dca7cd8..67be3a41a7c9 100644 --- a/stdlib/2/inspect.pyi +++ b/stdlib/2/inspect.pyi @@ -52,8 +52,7 @@ def isgetsetdescriptor(object: object) -> bool: ... def ismemberdescriptor(object: object) -> bool: ... # Retrieving source code -_SourceObjectType = Union[ModuleType, Type, MethodType, FunctionType, - TracebackType, FrameType, CodeType] +_SourceObjectType = Union[ModuleType, Type[Any], MethodType, FunctionType, TracebackType, FrameType, CodeType] def findsource(object: _SourceObjectType) -> Tuple[List[str], int]: ... def getabsfile(object: _SourceObjectType) -> str: ... @@ -69,13 +68,12 @@ def cleandoc(doc: str) -> str: ... def indentsize(line: str) -> int: ... # Classes and functions -def getclasstree(classes: List[type], unique: bool = ...) -> List[ - Union[Tuple[type, Tuple[type, ...]], list]]: ... +def getclasstree(classes: List[type], unique: bool = ...) -> List[Union[Tuple[type, Tuple[type, ...]], List[Any]]]: ... ArgSpec = NamedTuple('ArgSpec', [('args', List[str]), ('varargs', Optional[str]), ('keywords', Optional[str]), - ('defaults', tuple), + ('defaults', Tuple[Any, ...]), ]) ArgInfo = NamedTuple('ArgInfo', [('args', List[str]), diff --git a/stdlib/2/json.pyi b/stdlib/2/json.pyi index 84ed8b9c3fae..578e0cd0c507 100644 --- a/stdlib/2/json.pyi +++ b/stdlib/2/json.pyi @@ -36,7 +36,7 @@ def dump(obj: Any, def loads(s: Union[Text, bytes], encoding: Any = ..., cls: Optional[Type[JSONDecoder]] = ..., - object_hook: Optional[Callable[[Dict], Any]] = ..., + object_hook: Optional[Callable[[Dict[Any, Any]], Any]] = ..., parse_float: Optional[Callable[[str], Any]] = ..., parse_int: Optional[Callable[[str], Any]] = ..., parse_constant: Optional[Callable[[str], Any]] = ..., @@ -49,7 +49,7 @@ class _Reader(Protocol): def load(fp: _Reader, encoding: Optional[str] = ..., cls: Optional[Type[JSONDecoder]] = ..., - object_hook: Optional[Callable[[Dict], Any]] = ..., + object_hook: Optional[Callable[[Dict[Any, Any]], Any]] = ..., parse_float: Optional[Callable[[str], Any]] = ..., parse_int: Optional[Callable[[str], Any]] = ..., parse_constant: Optional[Callable[[str], Any]] = ..., diff --git a/stdlib/2/multiprocessing/dummy/__init__.pyi b/stdlib/2/multiprocessing/dummy/__init__.pyi index e8e02eb16eee..ea41a4cf8ada 100644 --- a/stdlib/2/multiprocessing/dummy/__init__.pyi +++ b/stdlib/2/multiprocessing/dummy/__init__.pyi @@ -14,7 +14,7 @@ from Queue import Queue class DummyProcess(threading.Thread): - _children: weakref.WeakKeyDictionary + _children: weakref.WeakKeyDictionary[Any, Any] _parent: threading.Thread _pid: None _start_called: bool @@ -42,10 +42,10 @@ class Value(object): JoinableQueue = Queue -def Array(typecode, sequence, lock=...) -> array.array: ... +def Array(typecode, sequence, lock=...) -> array.array[Any]: ... def Manager() -> Any: ... def Pool(processes=..., initializer=..., initargs=...) -> Any: ... -def active_children() -> List: ... +def active_children() -> List[Any]: ... def current_process() -> threading.Thread: ... def freeze_support() -> None: ... def shutdown() -> None: ... diff --git a/stdlib/2/multiprocessing/dummy/connection.pyi b/stdlib/2/multiprocessing/dummy/connection.pyi index a7a4f995fdb0..663d39434cef 100644 --- a/stdlib/2/multiprocessing/dummy/connection.pyi +++ b/stdlib/2/multiprocessing/dummy/connection.pyi @@ -15,7 +15,7 @@ class Connection(object): def poll(self, timeout=...) -> Any: ... class Listener(object): - _backlog_queue: Optional[Queue] + _backlog_queue: Optional[Queue[Any]] address: Any def __init__(self, address=..., family=..., backlog=...) -> None: ... def accept(self) -> Connection: ... diff --git a/stdlib/2/mutex.pyi b/stdlib/2/mutex.pyi index 8da8bfbaffce..fa41bbb4fcec 100644 --- a/stdlib/2/mutex.pyi +++ b/stdlib/2/mutex.pyi @@ -1,13 +1,12 @@ # Source: https://hg.python.org/cpython/file/2.7/Lib/mutex.py -from collections import deque -from typing import Any, Callable, TypeVar +from typing import Any, Callable, Deque, TypeVar _ArgType = TypeVar('_ArgType') class mutex: locked: bool - queue: deque + queue: Deque[Any] def __init__(self) -> None: ... def test(self) -> bool: ... def testandset(self) -> bool: ... diff --git a/stdlib/2/popen2.pyi b/stdlib/2/popen2.pyi index 23435b3a2a9f..b39ba5f074b0 100644 --- a/stdlib/2/popen2.pyi +++ b/stdlib/2/popen2.pyi @@ -5,24 +5,24 @@ _T = TypeVar('_T') class Popen3: sts: int - cmd: Iterable + cmd: Iterable[Any] pid: int tochild: TextIO fromchild: TextIO childerr: Optional[TextIO] - def __init__(self, cmd: Iterable = ..., capturestderr: bool = ..., bufsize: int = ...) -> None: ... + def __init__(self, cmd: Iterable[Any] = ..., capturestderr: bool = ..., bufsize: int = ...) -> None: ... def __del__(self) -> None: ... def poll(self, _deadstate: _T = ...) -> Union[int, _T]: ... def wait(self) -> int: ... class Popen4(Popen3): childerr: None - cmd: Iterable + cmd: Iterable[Any] pid: int tochild: TextIO fromchild: TextIO - def __init__(self, cmd: Iterable = ..., bufsize: int = ...) -> None: ... + def __init__(self, cmd: Iterable[Any] = ..., bufsize: int = ...) -> None: ... -def popen2(cmd: Iterable = ..., bufsize: int = ..., mode: str = ...) -> Tuple[TextIO, TextIO]: ... -def popen3(cmd: Iterable = ..., bufsize: int = ..., mode: str = ...) -> Tuple[TextIO, TextIO, TextIO]: ... -def popen4(cmd: Iterable = ..., bufsize: int = ..., mode: str = ...) -> Tuple[TextIO, TextIO]: ... +def popen2(cmd: Iterable[Any] = ..., bufsize: int = ..., mode: str = ...) -> Tuple[TextIO, TextIO]: ... +def popen3(cmd: Iterable[Any] = ..., bufsize: int = ..., mode: str = ...) -> Tuple[TextIO, TextIO, TextIO]: ... +def popen4(cmd: Iterable[Any] = ..., bufsize: int = ..., mode: str = ...) -> Tuple[TextIO, TextIO]: ... diff --git a/stdlib/2/repr.pyi b/stdlib/2/repr.pyi index ad89789e5a6c..a24e59bc9fec 100644 --- a/stdlib/2/repr.pyi +++ b/stdlib/2/repr.pyi @@ -1,3 +1,5 @@ +from typing import Any, List + class Repr: maxarray: int maxdeque: int @@ -25,7 +27,7 @@ class Repr: def repr_str(self, x, level: complex) -> str: ... def repr_tuple(self, x, level: complex) -> str: ... -def _possibly_sorted(x) -> list: ... +def _possibly_sorted(x) -> List[Any]: ... aRepr: Repr def repr(x) -> str: ... diff --git a/stdlib/2/sets.pyi b/stdlib/2/sets.pyi index a68994f2f2b6..3ec4cae2fc44 100644 --- a/stdlib/2/sets.pyi +++ b/stdlib/2/sets.pyi @@ -3,7 +3,7 @@ from typing import Any, Callable, Hashable, Iterable, Iterator, MutableMapping, _T = TypeVar('_T') _Setlike = Union[BaseSet[_T], Iterable[_T]] -_SelfT = TypeVar('_SelfT', bound=BaseSet) +_SelfT = TypeVar('_SelfT') class BaseSet(Iterable[_T]): def __init__(self) -> None: ... @@ -18,13 +18,13 @@ class BaseSet(Iterable[_T]): def __copy__(self: _SelfT) -> _SelfT: ... def __deepcopy__(self: _SelfT, memo: MutableMapping[int, BaseSet[_T]]) -> _SelfT: ... def __or__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... - def union(self: _SelfT, other: _Setlike) -> _SelfT: ... + def union(self: _SelfT, other: _Setlike[_T]) -> _SelfT: ... def __and__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... - def intersection(self: _SelfT, other: _Setlike) -> _SelfT: ... + def intersection(self: _SelfT, other: _Setlike[Any]) -> _SelfT: ... def __xor__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... - def symmetric_difference(self: _SelfT, other: _Setlike) -> _SelfT: ... + def symmetric_difference(self: _SelfT, other: _Setlike[_T]) -> _SelfT: ... def __sub__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... - def difference(self: _SelfT, other: _Setlike) -> _SelfT: ... + def difference(self: _SelfT, other: _Setlike[Any]) -> _SelfT: ... def __contains__(self, element: Any) -> bool: ... def issubset(self, other: BaseSet[_T]) -> bool: ... def issuperset(self, other: BaseSet[_T]) -> bool: ... @@ -34,20 +34,20 @@ class BaseSet(Iterable[_T]): def __gt__(self, other: BaseSet[_T]) -> bool: ... class ImmutableSet(BaseSet[_T], Hashable): - def __init__(self, iterable: Optional[_Setlike] = ...) -> None: ... + def __init__(self, iterable: Optional[_Setlike[_T]] = ...) -> None: ... def __hash__(self) -> int: ... class Set(BaseSet[_T]): - def __init__(self, iterable: Optional[_Setlike] = ...) -> None: ... - def __ior__(self, other: BaseSet[_T]) -> Set: ... - def union_update(self, other: _Setlike) -> None: ... - def __iand__(self, other: BaseSet[_T]) -> Set: ... - def intersection_update(self, other: _Setlike) -> None: ... - def __ixor__(self, other: BaseSet[_T]) -> Set: ... - def symmetric_difference_update(self, other: _Setlike) -> None: ... - def __isub__(self, other: BaseSet[_T]) -> Set: ... - def difference_update(self, other: _Setlike) -> None: ... - def update(self, iterable: _Setlike) -> None: ... + def __init__(self, iterable: Optional[_Setlike[_T]] = ...) -> None: ... + def __ior__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... + def union_update(self, other: _Setlike[_T]) -> None: ... + def __iand__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... + def intersection_update(self, other: _Setlike[Any]) -> None: ... + def __ixor__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... + def symmetric_difference_update(self, other: _Setlike[_T]) -> None: ... + def __isub__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... + def difference_update(self, other: _Setlike[Any]) -> None: ... + def update(self, iterable: _Setlike[_T]) -> None: ... def clear(self) -> None: ... def add(self, element: _T) -> None: ... def remove(self, element: _T) -> None: ... diff --git a/stdlib/2/shelve.pyi b/stdlib/2/shelve.pyi index d7d9b8c60188..15828bc1793a 100644 --- a/stdlib/2/shelve.pyi +++ b/stdlib/2/shelve.pyi @@ -2,7 +2,7 @@ from typing import Any, Dict, Iterator, List, Optional, Tuple import collections -class Shelf(collections.MutableMapping): +class Shelf(collections.MutableMapping[Any, Any]): def __init__(self, dict: Dict[Any, Any], protocol: Optional[int] = ..., writeback: bool = ..., keyencoding: str = ...) -> None: ... def __iter__(self) -> Iterator[str]: ... def keys(self) -> List[Any]: ... diff --git a/stdlib/2/sre_parse.pyi b/stdlib/2/sre_parse.pyi index beabb40946b6..d23753527d12 100644 --- a/stdlib/2/sre_parse.pyi +++ b/stdlib/2/sre_parse.pyi @@ -4,10 +4,10 @@ from typing import Any, Dict, Iterable, List, Match, Optional, Pattern as _Patte SPECIAL_CHARS: str REPEAT_CHARS: str -DIGITS: Set -OCTDIGITS: Set -HEXDIGITS: Set -WHITESPACE: Set +DIGITS: Set[Any] +OCTDIGITS: Set[Any] +HEXDIGITS: Set[Any] +WHITESPACE: Set[Any] ESCAPES: Dict[str, Tuple[str, int]] CATEGORIES: Dict[str, Union[Tuple[str, str], Tuple[str, List[Tuple[str, str]]]]] FLAGS: Dict[str, int] @@ -59,5 +59,5 @@ def isdigit(char: str) -> bool: ... def isname(name: str) -> bool: ... def parse(str: str, flags: int = ..., pattern: Pattern = ...) -> SubPattern: ... _Template = Tuple[List[Tuple[int, int]], List[Optional[int]]] -def parse_template(source: str, pattern: _Pattern) -> _Template: ... -def expand_template(template: _Template, match: Match) -> str: ... +def parse_template(source: str, pattern: _Pattern[Any]) -> _Template: ... +def expand_template(template: _Template, match: Match[Any]) -> str: ... diff --git a/stdlib/2/subprocess.pyi b/stdlib/2/subprocess.pyi index 672efbf8c71e..54dd0dbd3bc8 100644 --- a/stdlib/2/subprocess.pyi +++ b/stdlib/2/subprocess.pyi @@ -105,8 +105,6 @@ class Popen(Generic[_T]): def send_signal(self, signal: int) -> None: ... def terminate(self) -> None: ... def kill(self) -> None: ... - def __enter__(self) -> Popen: ... - def __exit__(self, type, value, traceback) -> None: ... def list2cmdline(seq: Sequence[str]) -> str: ... # undocumented diff --git a/stdlib/2/tempfile.pyi b/stdlib/2/tempfile.pyi index 4233cf72f179..536b391ad4d0 100644 --- a/stdlib/2/tempfile.pyi +++ b/stdlib/2/tempfile.pyi @@ -19,9 +19,9 @@ class _RandomNameSequence: class _TemporaryFileWrapper(IO[str]): delete: bool - file: IO + file: IO[str] name: Any - def __init__(self, file: IO, name: Any, delete: bool = ...) -> None: ... + def __init__(self, file: IO[str], name: Any, delete: bool = ...) -> None: ... def __del__(self) -> None: ... def __enter__(self) -> _TemporaryFileWrapper: ... def __exit__(self, exc, value, tb) -> Optional[bool]: ... diff --git a/stdlib/2/types.pyi b/stdlib/2/types.pyi index 93360e7dec35..47c52e88a29d 100644 --- a/stdlib/2/types.pyi +++ b/stdlib/2/types.pyi @@ -103,7 +103,7 @@ class UnboundMethodType: __name__: str __func__ = im_func __self__ = im_self - def __init__(self, func: Callable, obj: object) -> None: ... + def __init__(self, func: Callable[..., Any], obj: object) -> None: ... def __call__(self, *args: Any, **kwargs: Any) -> Any: ... class InstanceType(object): ... @@ -154,7 +154,7 @@ class EllipsisType: ... class DictProxyType: # TODO is it possible to have non-string keys? # no __init__ - def copy(self) -> dict: ... + def copy(self) -> Dict[Any, Any]: ... def get(self, key: str, default: _T = ...) -> Union[Any, _T]: ... def has_key(self, key: str) -> bool: ... def items(self) -> List[Tuple[str, Any]]: ... diff --git a/stdlib/2/typing.pyi b/stdlib/2/typing.pyi index 0d10952b5ae6..d45aba1da6b7 100644 --- a/stdlib/2/typing.pyi +++ b/stdlib/2/typing.pyi @@ -69,7 +69,7 @@ _KT_co = TypeVar('_KT_co', covariant=True) # Key type covariant containers. _VT_co = TypeVar('_VT_co', covariant=True) # Value type covariant containers. _T_contra = TypeVar('_T_contra', contravariant=True) # Ditto contravariant. _TC = TypeVar('_TC', bound=Type[object]) -_C = TypeVar("_C", bound=Callable) +_C = TypeVar("_C", bound=Callable[..., Any]) def runtime_checkable(cls: _TC) -> _TC: ... @@ -447,8 +447,9 @@ class Pattern(Generic[AnyStr]): # Functions -def get_type_hints(obj: Callable, globalns: Optional[dict[Text, Any]] = ..., - localns: Optional[dict[Text, Any]] = ...) -> None: ... +def get_type_hints( + obj: Callable[..., Any], globalns: Optional[Dict[Text, Any]] = ..., localns: Optional[Dict[Text, Any]] = ..., +) -> None: ... @overload def cast(tp: Type[_T], obj: Any) -> _T: ... @@ -458,7 +459,7 @@ def cast(tp: str, obj: Any) -> Any: ... # Type constructors # NamedTuple is special-cased in the type checker -class NamedTuple(tuple): +class NamedTuple(Tuple[Any, ...]): _fields: Tuple[str, ...] def __init__(self, typename: Text, fields: Iterable[Tuple[Text, Any]] = ..., *, @@ -467,7 +468,7 @@ class NamedTuple(tuple): @classmethod def _make(cls: Type[_T], iterable: Iterable[Any]) -> _T: ... - def _asdict(self) -> dict: ... + def _asdict(self) -> Dict[str, Any]: ... def _replace(self: _T, **kwargs: Any) -> _T: ... # Internal mypy fallback type for all typed dicts (does not exist at runtime) diff --git a/stdlib/2/xmlrpclib.pyi b/stdlib/2/xmlrpclib.pyi index abf40987e61d..d1d293718dae 100644 --- a/stdlib/2/xmlrpclib.pyi +++ b/stdlib/2/xmlrpclib.pyi @@ -12,7 +12,7 @@ from gzip import GzipFile _Unmarshaller = Any _timeTuple = Tuple[int, int, int, int, int, int, int, int, int] # Represents types that can be compared against a DateTime object -_dateTimeComp = Union[AnyStr, DateTime, datetime, _timeTuple] +_dateTimeComp = Union[unicode, DateTime, datetime] # A "host description" used by Transport factories _hostDesc = Union[str, Tuple[str, Mapping[Any, Any]]] @@ -55,26 +55,26 @@ Boolean: Type[bool] class DateTime: value: str def __init__(self, value: Union[str, unicode, datetime, float, int, _timeTuple, struct_time] = ...) -> None: ... - def make_comparable(self, other: _dateTimeComp) -> Tuple[_dateTimeComp, _dateTimeComp]: ... + def make_comparable(self, other: _dateTimeComp) -> Tuple[unicode, unicode]: ... def __lt__(self, other: _dateTimeComp) -> bool: ... def __le__(self, other: _dateTimeComp) -> bool: ... def __gt__(self, other: _dateTimeComp) -> bool: ... def __ge__(self, other: _dateTimeComp) -> bool: ... - def __eq__(self, other: _dateTimeComp) -> bool: ... - def __ne__(self, other: _dateTimeComp) -> bool: ... + def __eq__(self, other: _dateTimeComp) -> bool: ... # type: ignore + def __ne__(self, other: _dateTimeComp) -> bool: ... # type: ignore def timetuple(self) -> struct_time: ... def __cmp__(self, other: _dateTimeComp) -> int: ... def decode(self, data: Any) -> None: ... - def encode(self, out: IO) -> None: ... + def encode(self, out: IO[str]) -> None: ... class Binary: data: str def __init__(self, data: Optional[str] = ...) -> None: ... def __cmp__(self, other: Any) -> int: ... def decode(self, data: str) -> None: ... - def encode(self, out: IO) -> None: ... + def encode(self, out: IO[str]) -> None: ... -WRAPPERS: tuple +WRAPPERS: Tuple[Type[Any], ...] # Still part of the public API, but see http://bugs.python.org/issue1773632 FastParser: None @@ -104,7 +104,28 @@ class Marshaller: allow_none: bool def __init__(self, encoding: Optional[str] = ..., allow_none: bool = ...) -> None: ... dispatch: Mapping[type, Callable[[Marshaller, str, Callable[[str], None]], None]] - def dumps(self, values: Union[Iterable[Union[None, int, bool, long, float, str, unicode, List, Tuple, Mapping, datetime, InstanceType]], Fault]) -> str: ... + def dumps( + self, + values: Union[ + Iterable[ + Union[ + None, + int, + bool, + long, + float, + str, + unicode, + List[Any], + Tuple[Any, ...], + Mapping[Any, Any], + datetime, + InstanceType, + ], + ], + Fault, + ], + ) -> str: ... def dump_nil(self, value: None, write: Callable[[str], None]) -> None: ... def dump_int(self, value: int, write: Callable[[str], None]) -> None: ... def dump_bool(self, value: bool, write: Callable[[str], None]) -> None: ... @@ -112,15 +133,20 @@ class Marshaller: def dump_double(self, value: float, write: Callable[[str], None]) -> None: ... def dump_string(self, value: str, write: Callable[[str], None], escape: Callable[[AnyStr, Callable[[AnyStr, AnyStr, AnyStr], AnyStr]], AnyStr] = ...) -> None: ... def dump_unicode(self, value: unicode, write: Callable[[str], None], escape: Callable[[AnyStr, Callable[[AnyStr, AnyStr, AnyStr], AnyStr]], AnyStr] = ...) -> None: ... - def dump_array(self, value: Union[List, Tuple], write: Callable[[str], None]) -> None: ... - def dump_struct(self, value: Mapping, write: Callable[[str], None], escape: Callable[[AnyStr, Callable[[AnyStr, AnyStr, AnyStr], AnyStr]], AnyStr] = ...) -> None: ... + def dump_array(self, value: Iterable[Any], write: Callable[[str], None]) -> None: ... + def dump_struct( + self, + value: Mapping[unicode, Any], + write: Callable[[str], None], + escape: Callable[[AnyStr, Callable[[AnyStr, AnyStr, AnyStr], AnyStr]], AnyStr] = ..., + ) -> None: ... def dump_datetime(self, value: datetime, write: Callable[[str], None]) -> None: ... def dump_instance(self, value: InstanceType, write: Callable[[str], None]) -> None: ... class Unmarshaller: def append(self, object: Any) -> None: ... def __init__(self, use_datetime: bool = ...) -> None: ... - def close(self) -> tuple: ... + def close(self) -> Tuple[Any, ...]: ... def getmethodname(self) -> Optional[str]: ... def xml(self, encoding: str, standalone: bool) -> None: ... def start(self, tag: str, attrs: Any) -> None: ... @@ -143,9 +169,9 @@ class Unmarshaller: def end_methodName(self, data: str) -> None: ... class _MultiCallMethod: - def __init__(self, call_list: List[Tuple[str, tuple]], name: str) -> None: ... + def __init__(self, call_list: List[Tuple[str, Tuple[Any, ...]]], name: str) -> None: ... class MultiCallIterator: - def __init__(self, results: List) -> None: ... + def __init__(self, results: List[Any]) -> None: ... class MultiCall: def __init__(self, server: ServerProxy) -> None: ... @@ -153,19 +179,25 @@ class MultiCall: def __call__(self) -> MultiCallIterator: ... def getparser(use_datetime: bool = ...) -> Tuple[Union[ExpatParser, SlowParser], Unmarshaller]: ... -def dumps(params: Union[tuple, Fault], methodname: Optional[str] = ..., methodresponse: Optional[bool] = ..., encoding: Optional[str] = ..., allow_none: bool = ...) -> str: ... -def loads(data: str, use_datetime: bool = ...) -> Tuple[tuple, Optional[str]]: ... +def dumps( + params: Union[Tuple[Any, ...], Fault], + methodname: Optional[str] = ..., + methodresponse: Optional[bool] = ..., + encoding: Optional[str] = ..., + allow_none: bool = ..., +) -> str: ... +def loads(data: str, use_datetime: bool = ...) -> Tuple[Tuple[Any, ...], Optional[str]]: ... def gzip_encode(data: str) -> str: ... def gzip_decode(data: str, max_decode: int = ...) -> str: ... class GzipDecodedResponse(GzipFile): - stringio: StringIO + stringio: StringIO[Any] def __init__(self, response: HTTPResponse) -> None: ... def close(self): ... class _Method: - def __init__(self, send: Callable[[str, tuple], Any], name: str) -> None: ... + def __init__(self, send: Callable[[str, Tuple[Any, ...]], Any], name: str) -> None: ... def __getattr__(self, name: str) -> _Method: ... def __call__(self, *args: Any) -> Any: ... @@ -174,9 +206,9 @@ class Transport: accept_gzip_encoding: bool encode_threshold: Optional[int] def __init__(self, use_datetime: bool = ...) -> None: ... - def request(self, host: _hostDesc, handler: str, request_body: str, verbose: bool = ...) -> tuple: ... + def request(self, host: _hostDesc, handler: str, request_body: str, verbose: bool = ...) -> Tuple[Any, ...]: ... verbose: bool - def single_request(self, host: _hostDesc, handler: str, request_body: str, verbose: bool = ...) -> tuple: ... + def single_request(self, host: _hostDesc, handler: str, request_body: str, verbose: bool = ...) -> Tuple[Any, ...]: ... def getparser(self) -> Tuple[Union[ExpatParser, SlowParser], Unmarshaller]: ... def get_host_info(self, host: _hostDesc) -> Tuple[str, Optional[List[Tuple[str, str]]], Optional[Mapping[Any, Any]]]: ... def make_connection(self, host: _hostDesc) -> HTTPConnection: ... @@ -185,7 +217,7 @@ class Transport: def send_host(self, connection: HTTPConnection, host: str) -> None: ... def send_user_agent(self, connection: HTTPConnection) -> None: ... def send_content(self, connection: HTTPConnection, request_body: str) -> None: ... - def parse_response(self, response: HTTPResponse) -> tuple: ... + def parse_response(self, response: HTTPResponse) -> Tuple[Any, ...]: ... class SafeTransport(Transport): def __init__(self, use_datetime: bool = ..., context: Optional[SSLContext] = ...) -> None: ... diff --git a/stdlib/2and3/builtins.pyi b/stdlib/2and3/builtins.pyi index 9b4c83dc8949..62052cfb7186 100644 --- a/stdlib/2and3/builtins.pyi +++ b/stdlib/2and3/builtins.pyi @@ -870,7 +870,7 @@ class tuple(Sequence[_T_co], Generic[_T_co]): @overload def __add__(self, x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ... @overload - def __add__(self, x: tuple) -> tuple: ... + def __add__(self, x: Tuple[Any, ...]) -> Tuple[Any, ...]: ... def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ... def count(self, x: Any) -> int: ... diff --git a/stdlib/3/_threading_local.pyi b/stdlib/3/_threading_local.pyi index a286d2dd54cc..638c93f8b05a 100644 --- a/stdlib/3/_threading_local.pyi +++ b/stdlib/3/_threading_local.pyi @@ -7,7 +7,7 @@ localdict = Dict[Any, Any] class _localimpl: key: str - dicts: Dict[int, Tuple[ReferenceType, localdict]] + dicts: Dict[int, Tuple[ReferenceType[Any], localdict]] def __init__(self) -> None: ... def get_dict(self) -> localdict: ... def create_dict(self) -> localdict: ... diff --git a/stdlib/3/_tracemalloc.pyi b/stdlib/3/_tracemalloc.pyi index 21d00332ad37..a46db2419f20 100644 --- a/stdlib/3/_tracemalloc.pyi +++ b/stdlib/3/_tracemalloc.pyi @@ -3,7 +3,7 @@ # for a more precise manual annotation of this module. # Feel free to edit the source below, but remove this header when you do. -from typing import Any +from typing import Any, Tuple def _get_object_traceback(*args, **kwargs) -> Any: ... @@ -14,7 +14,7 @@ def clear_traces() -> None: ... def get_traceback_limit() -> int: ... -def get_traced_memory() -> tuple: ... +def get_traced_memory() -> Tuple[Any, ...]: ... def get_tracemalloc_memory() -> Any: ... diff --git a/stdlib/3/_warnings.pyi b/stdlib/3/_warnings.pyi index 6529c40b9993..c055b2a1d080 100644 --- a/stdlib/3/_warnings.pyi +++ b/stdlib/3/_warnings.pyi @@ -1,11 +1,11 @@ -from typing import Any, List, Optional, Type +from typing import Any, Dict, List, Optional, Tuple, Type _defaultaction: str -_onceregistry: dict -filters: List[tuple] +_onceregistry: Dict[Any, Any] +filters: List[Tuple[Any, ...]] def warn(message: Warning, category: Optional[Type[Warning]] = ..., stacklevel: int = ...) -> None: ... def warn_explicit(message: Warning, category: Optional[Type[Warning]], filename: str, lineno: int, - module: Any = ..., registry: dict = ..., - module_globals: dict = ...) -> None: ... + module: Any = ..., registry: Dict[Any, Any] = ..., + module_globals: Dict[Any, Any] = ...) -> None: ... diff --git a/stdlib/3/asyncio/base_events.pyi b/stdlib/3/asyncio/base_events.pyi index 6a80cbdec387..8a959a9ee0dc 100644 --- a/stdlib/3/asyncio/base_events.pyi +++ b/stdlib/3/asyncio/base_events.pyi @@ -61,7 +61,7 @@ class BaseEventLoop(AbstractEventLoop, metaclass=ABCMeta): family: int = ..., type: int = ..., proto: int = ..., flags: int = ...) -> Generator[Any, None, List[Tuple[int, int, int, str, Tuple[Any, ...]]]]: ... @coroutine - def getnameinfo(self, sockaddr: tuple, flags: int = ...) -> Generator[Any, None, Tuple[str, int]]: ... + def getnameinfo(self, sockaddr: Tuple[Any, ...], flags: int = ...) -> Generator[Any, None, Tuple[str, int]]: ... if sys.version_info >= (3, 7): async def sock_sendfile(self, sock: socket, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *, fallback: bool = ...) -> int: ... diff --git a/stdlib/3/asyncio/events.pyi b/stdlib/3/asyncio/events.pyi index e779d2a8d172..66f7c9f9e134 100644 --- a/stdlib/3/asyncio/events.pyi +++ b/stdlib/3/asyncio/events.pyi @@ -107,7 +107,7 @@ class AbstractEventLoop(metaclass=ABCMeta): flags: int = ...) -> Generator[Any, None, List[Tuple[int, int, int, str, Tuple[Any, ...]]]]: ... @abstractmethod @coroutine - def getnameinfo(self, sockaddr: tuple, flags: int = ...) -> Generator[Any, None, Tuple[str, int]]: ... + def getnameinfo(self, sockaddr: Tuple[Any, ...], flags: int = ...) -> Generator[Any, None, Tuple[str, int]]: ... if sys.version_info >= (3, 7): @abstractmethod async def sock_sendfile(self, sock: socket, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *, diff --git a/stdlib/3/asyncio/futures.pyi b/stdlib/3/asyncio/futures.pyi index b4323c0189d4..37bd02c30fcd 100644 --- a/stdlib/3/asyncio/futures.pyi +++ b/stdlib/3/asyncio/futures.pyi @@ -14,7 +14,7 @@ if sys.version_info >= (3, 7): __all__: List[str] _T = TypeVar('_T') -_S = TypeVar('_S', bound=Future) +_S = TypeVar('_S') class InvalidStateError(Error): ... diff --git a/stdlib/3/asyncio/tasks.pyi b/stdlib/3/asyncio/tasks.pyi index 830af19d49bb..05b590eb0430 100644 --- a/stdlib/3/asyncio/tasks.pyi +++ b/stdlib/3/asyncio/tasks.pyi @@ -95,9 +95,9 @@ def wait_for(fut: _FutureT[_T], timeout: Optional[float], class Task(Future[_T], Generic[_T]): @classmethod - def current_task(cls, loop: Optional[AbstractEventLoop] = ...) -> Task: ... + def current_task(cls, loop: Optional[AbstractEventLoop] = ...) -> Task[Any]: ... @classmethod - def all_tasks(cls, loop: Optional[AbstractEventLoop] = ...) -> Set[Task]: ... + def all_tasks(cls, loop: Optional[AbstractEventLoop] = ...) -> Set[Task[Any]]: ... def __init__(self, coro: Union[Generator[Any, None, _T], Awaitable[_T]], *, loop: AbstractEventLoop = ...) -> None: ... def __repr__(self) -> str: ... def get_stack(self, *, limit: int = ...) -> List[FrameType]: ... @@ -107,6 +107,6 @@ class Task(Future[_T], Generic[_T]): def _wakeup(self, future: Future[Any]) -> None: ... if sys.version_info >= (3, 7): - def all_tasks(loop: Optional[AbstractEventLoop] = ...) -> Set[Task]: ... - def create_task(coro: Union[Generator[Any, None, _T], Awaitable[_T]]) -> Task: ... - def current_task(loop: Optional[AbstractEventLoop] = ...) -> Optional[Task]: ... + def all_tasks(loop: Optional[AbstractEventLoop] = ...) -> Set[Task[Any]]: ... + def create_task(coro: Union[Generator[Any, None, _T], Awaitable[_T]]) -> Task[Any]: ... + def current_task(loop: Optional[AbstractEventLoop] = ...) -> Optional[Task[Any]]: ... diff --git a/stdlib/3/collections/__init__.pyi b/stdlib/3/collections/__init__.pyi index a6cecdfc794d..46d3644dc60a 100644 --- a/stdlib/3/collections/__init__.pyi +++ b/stdlib/3/collections/__init__.pyi @@ -47,16 +47,27 @@ _VT = TypeVar('_VT') # namedtuple is special-cased in the type checker; the initializer is ignored. if sys.version_info >= (3, 7): - def namedtuple(typename: str, field_names: Union[str, Iterable[str]], *, - rename: bool = ..., module: Optional[str] = ..., defaults: Optional[Iterable[Any]] = ...) -> Type[tuple]: ... + def namedtuple( + typename: str, + field_names: Union[str, Iterable[str]], + *, + rename: bool = ..., + module: Optional[str] = ..., + defaults: Optional[Iterable[Any]] = ..., + ) -> Type[Tuple[Any, ...]]: ... elif sys.version_info >= (3, 6): - def namedtuple(typename: str, field_names: Union[str, Iterable[str]], *, - verbose: bool = ..., rename: bool = ..., module: Optional[str] = ...) -> Type[tuple]: ... + def namedtuple( + typename: str, + field_names: Union[str, Iterable[str]], + *, + verbose: bool = ..., + rename: bool = ..., + module: Optional[str] = ..., + ) -> Type[Tuple[Any, ...]]: ... else: - def namedtuple(typename: str, field_names: Union[str, Iterable[str]], - verbose: bool = ..., rename: bool = ...) -> Type[tuple]: ... - -_UserDictT = TypeVar('_UserDictT', bound=UserDict) + def namedtuple( + typename: str, field_names: Union[str, Iterable[str]], verbose: bool = ..., rename: bool = ..., + ) -> Type[Tuple[Any, ...]]: ... class UserDict(MutableMapping[_KT, _VT]): data: Dict[_KT, _VT] @@ -67,11 +78,9 @@ class UserDict(MutableMapping[_KT, _VT]): def __delitem__(self, key: _KT) -> None: ... def __iter__(self) -> Iterator[_KT]: ... def __contains__(self, key: object) -> bool: ... - def copy(self: _UserDictT) -> _UserDictT: ... + def copy(self: _S) -> _S: ... @classmethod - def fromkeys(cls: Type[_UserDictT], iterable: Iterable[_KT], value: Optional[_VT] = ...) -> _UserDictT: ... - -_UserListT = TypeVar('_UserListT', bound=UserList) + def fromkeys(cls: Type[_S], iterable: Iterable[_KT], value: Optional[_VT] = ...) -> _S: ... class UserList(MutableSequence[_T]): data: List[_T] @@ -91,16 +100,16 @@ class UserList(MutableSequence[_T]): @overload def __setitem__(self, i: slice, o: Iterable[_T]) -> None: ... def __delitem__(self, i: Union[int, slice]) -> None: ... - def __add__(self: _UserListT, other: Iterable[_T]) -> _UserListT: ... - def __iadd__(self: _UserListT, other: Iterable[_T]) -> _UserListT: ... - def __mul__(self: _UserListT, n: int) -> _UserListT: ... - def __imul__(self: _UserListT, n: int) -> _UserListT: ... + def __add__(self: _S, other: Iterable[_T]) -> _S: ... + def __iadd__(self: _S, other: Iterable[_T]) -> _S: ... + def __mul__(self: _S, n: int) -> _S: ... + def __imul__(self: _S, n: int) -> _S: ... def append(self, item: _T) -> None: ... def insert(self, i: int, item: _T) -> None: ... def pop(self, i: int = ...) -> _T: ... def remove(self, item: _T) -> None: ... def clear(self) -> None: ... - def copy(self: _UserListT) -> _UserListT: ... + def copy(self: _S) -> _S: ... def count(self, item: _T) -> int: ... def index(self, item: _T, *args: Any) -> int: ... def reverse(self) -> None: ... @@ -233,8 +242,6 @@ class deque(MutableSequence[_T], Generic[_T]): def __mul__(self, other: int) -> deque[_T]: ... def __imul__(self, other: int) -> None: ... -_CounterT = TypeVar('_CounterT', bound=Counter) - class Counter(Dict[_T, int], Generic[_T]): @overload def __init__(self, **kwargs: int) -> None: ... @@ -242,7 +249,7 @@ class Counter(Dict[_T, int], Generic[_T]): def __init__(self, mapping: Mapping[_T, int]) -> None: ... @overload def __init__(self, iterable: Iterable[_T]) -> None: ... - def copy(self: _CounterT) -> _CounterT: ... + def copy(self: _S) -> _S: ... def elements(self) -> Iterator[_T]: ... def most_common(self, n: Optional[int] = ...) -> List[Tuple[_T, int]]: ... @@ -275,8 +282,6 @@ class Counter(Dict[_T, int], Generic[_T]): def __iand__(self, other: Counter[_T]) -> Counter[_T]: ... def __ior__(self, other: Counter[_T]) -> Counter[_T]: ... -_OrderedDictT = TypeVar('_OrderedDictT', bound=OrderedDict) - class _OrderedDictKeysView(KeysView[_KT], Reversible[_KT]): def __reversed__(self) -> Iterator[_KT]: ... class _OrderedDictItemsView(ItemsView[_KT, _VT], Reversible[Tuple[_KT, _VT]]): @@ -287,14 +292,12 @@ class _OrderedDictValuesView(ValuesView[_VT], Reversible[_VT]): class OrderedDict(Dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]): def popitem(self, last: bool = ...) -> Tuple[_KT, _VT]: ... def move_to_end(self, key: _KT, last: bool = ...) -> None: ... - def copy(self: _OrderedDictT) -> _OrderedDictT: ... + def copy(self: _S) -> _S: ... def __reversed__(self) -> Iterator[_KT]: ... def keys(self) -> _OrderedDictKeysView[_KT]: ... def items(self) -> _OrderedDictItemsView[_KT, _VT]: ... def values(self) -> _OrderedDictValuesView[_VT]: ... -_DefaultDictT = TypeVar('_DefaultDictT', bound=defaultdict) - class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]): default_factory: Optional[Callable[[], _VT]] @@ -318,7 +321,7 @@ class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]): iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... def __missing__(self, key: _KT) -> _VT: ... # TODO __reversed__ - def copy(self: _DefaultDictT) -> _DefaultDictT: ... + def copy(self: _S) -> _S: ... class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __init__(self, *maps: Mapping[_KT, _VT]) -> None: ... diff --git a/stdlib/3/compileall.pyi b/stdlib/3/compileall.pyi index 0e0b11748d73..276cb5bef304 100644 --- a/stdlib/3/compileall.pyi +++ b/stdlib/3/compileall.pyi @@ -2,7 +2,7 @@ import os import sys -from typing import Optional, Union, Pattern +from typing import Any, Optional, Union, Pattern if sys.version_info < (3, 6): _Path = Union[str, bytes] @@ -12,6 +12,24 @@ else: _SuccessType = int # rx can be any object with a 'search' method; once we have Protocols we can change the type -def compile_dir(dir: _Path, maxlevels: int = ..., ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern] = ..., quiet: int = ..., legacy: bool = ..., optimize: int = ..., workers: int = ...) -> _SuccessType: ... -def compile_file(fullname: _Path, ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern] = ..., quiet: int = ..., legacy: bool = ..., optimize: int = ...) -> _SuccessType: ... +def compile_dir( + dir: _Path, + maxlevels: int = ..., + ddir: Optional[_Path] = ..., + force: bool = ..., + rx: Optional[Pattern[Any]] = ..., + quiet: int = ..., + legacy: bool = ..., + optimize: int = ..., + workers: int = ..., +) -> _SuccessType: ... +def compile_file( + fullname: _Path, + ddir: Optional[_Path] = ..., + force: bool = ..., + rx: Optional[Pattern[Any]] = ..., + quiet: int = ..., + legacy: bool = ..., + optimize: int = ..., +) -> _SuccessType: ... def compile_path(skip_curdir: bool = ..., maxlevels: int = ..., force: bool = ..., quiet: int = ..., legacy: bool = ..., optimize: int = ...) -> _SuccessType: ... diff --git a/stdlib/3/concurrent/futures/_base.pyi b/stdlib/3/concurrent/futures/_base.pyi index 6d454fbe8388..00ff41d76959 100644 --- a/stdlib/3/concurrent/futures/_base.pyi +++ b/stdlib/3/concurrent/futures/_base.pyi @@ -62,25 +62,25 @@ def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: class _Waiter: event: threading.Event - finished_futures: List[Future] + finished_futures: List[Future[Any]] def __init__(self) -> None: ... - def add_result(self, future: Future) -> None: ... - def add_exception(self, future: Future) -> None: ... - def add_cancelled(self, future: Future) -> None: ... + def add_result(self, future: Future[Any]) -> None: ... + def add_exception(self, future: Future[Any]) -> None: ... + def add_cancelled(self, future: Future[Any]) -> None: ... class _AsCompletedWaiter(_Waiter): lock: threading.Lock def __init__(self) -> None: ... - def add_result(self, future: Future) -> None: ... - def add_exception(self, future: Future) -> None: ... - def add_cancelled(self, future: Future) -> None: ... + def add_result(self, future: Future[Any]) -> None: ... + def add_exception(self, future: Future[Any]) -> None: ... + def add_cancelled(self, future: Future[Any]) -> None: ... class _FirstCompletedWaiter(_Waiter): - def add_result(self, future: Future) -> None: ... - def add_exception(self, future: Future) -> None: ... - def add_cancelled(self, future: Future) -> None: ... + def add_result(self, future: Future[Any]) -> None: ... + def add_exception(self, future: Future[Any]) -> None: ... + def add_cancelled(self, future: Future[Any]) -> None: ... class _AllCompletedWaiter(_Waiter): @@ -88,13 +88,13 @@ class _AllCompletedWaiter(_Waiter): stop_on_exception: bool lock: threading.Lock def __init__(self, num_pending_calls: int, stop_on_exception: bool) -> None: ... - def add_result(self, future: Future) -> None: ... - def add_exception(self, future: Future) -> None: ... - def add_cancelled(self, future: Future) -> None: ... + def add_result(self, future: Future[Any]) -> None: ... + def add_exception(self, future: Future[Any]) -> None: ... + def add_cancelled(self, future: Future[Any]) -> None: ... class _AcquireFutures: - futures: Iterable[Future] - def __init__(self, futures: Iterable[Future]) -> None: ... + futures: Iterable[Future[Any]] + def __init__(self, futures: Iterable[Future[Any]]) -> None: ... def __enter__(self) -> None: ... def __exit__(self, *args: Any) -> None: ... diff --git a/stdlib/3/concurrent/futures/thread.pyi b/stdlib/3/concurrent/futures/thread.pyi index c4f895d7a543..82c8ddd03d94 100644 --- a/stdlib/3/concurrent/futures/thread.pyi +++ b/stdlib/3/concurrent/futures/thread.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Optional, Tuple, TypeVar, Generic +from typing import Any, Callable, Iterable, Mapping, Optional, Tuple, TypeVar, Generic from ._base import Executor, Future import sys @@ -22,10 +22,9 @@ class ThreadPoolExecutor(Executor): class _WorkItem(Generic[_S]): - future: Future - fn: Callable[[Future[_S]], Any] - args: Any - kwargs: Any - def __init__(self, future: Future, fn: Callable[[Future[_S]], Any], args: Any, - kwargs: Any) -> None: ... + future: Future[_S] + fn: Callable[..., _S] + args: Iterable[Any] + kwargs: Mapping[str, Any] + def __init__(self, future: Future[_S], fn: Callable[..., _S], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ... def run(self) -> None: ... diff --git a/stdlib/3/configparser.pyi b/stdlib/3/configparser.pyi index 3f59b611b865..8b87e06453b9 100644 --- a/stdlib/3/configparser.pyi +++ b/stdlib/3/configparser.pyi @@ -177,7 +177,7 @@ class SectionProxy(MutableMapping[str, str]): def __getattr__(self, key: str) -> Callable[..., Any]: ... class ConverterMapping(MutableMapping[str, Optional[_converter]]): - GETTERCRE: Pattern + GETTERCRE: Pattern[Any] def __init__(self, parser: RawConfigParser) -> None: ... def __getitem__(self, key: str) -> _converter: ... def __setitem__(self, key: str, value: Optional[_converter]) -> None: ... diff --git a/stdlib/3/http/cookies.pyi b/stdlib/3/http/cookies.pyi index 1e1091ba1c4a..dfd6df88cba1 100644 --- a/stdlib/3/http/cookies.pyi +++ b/stdlib/3/http/cookies.pyi @@ -2,7 +2,7 @@ from typing import Generic, Dict, List, Mapping, MutableMapping, Optional, TypeVar, Union, Any -_DataType = Union[str, Mapping[str, Union[str, Morsel]]] +_DataType = Union[str, Mapping[str, Union[str, Morsel[Any]]]] _T = TypeVar('_T') class CookieError(Exception): ... @@ -18,7 +18,7 @@ class Morsel(Dict[str, Any], Generic[_T]): def js_output(self, attrs: Optional[List[str]] = ...) -> str: ... def OutputString(self, attrs: Optional[List[str]] = ...) -> str: ... -class BaseCookie(Dict[str, Morsel], Generic[_T]): +class BaseCookie(Dict[str, Morsel[_T]], Generic[_T]): def __init__(self, input: Optional[_DataType] = ...) -> None: ... def value_decode(self, val: str) -> _T: ... def value_encode(self, val: _T) -> str: ... @@ -26,6 +26,6 @@ class BaseCookie(Dict[str, Morsel], Generic[_T]): sep: str = ...) -> str: ... def js_output(self, attrs: Optional[List[str]] = ...) -> str: ... def load(self, rawdata: _DataType) -> None: ... - def __setitem__(self, key: str, value: Union[str, Morsel]) -> None: ... + def __setitem__(self, key: str, value: Union[str, Morsel[_T]]) -> None: ... -class SimpleCookie(BaseCookie): ... +class SimpleCookie(BaseCookie[_T], Generic[_T]): ... diff --git a/stdlib/3/inspect.pyi b/stdlib/3/inspect.pyi index cd3ae936440e..5c518b81baab 100644 --- a/stdlib/3/inspect.pyi +++ b/stdlib/3/inspect.pyi @@ -77,8 +77,7 @@ def ismemberdescriptor(object: object) -> bool: ... # # Retrieving source code # -_SourceObjectType = Union[ModuleType, Type, MethodType, FunctionType, - TracebackType, FrameType, CodeType] +_SourceObjectType = Union[ModuleType, Type[Any], MethodType, FunctionType, TracebackType, FrameType, CodeType] def findsource(object: _SourceObjectType) -> Tuple[List[str], int]: ... def getabsfile(object: _SourceObjectType) -> str: ... @@ -174,7 +173,7 @@ def getclasstree(classes: List[type], unique: bool = ...) -> Any: ... ArgSpec = NamedTuple('ArgSpec', [('args', List[str]), ('varargs', str), ('keywords', str), - ('defaults', tuple), + ('defaults', Tuple[Any, ...]), ]) Arguments = NamedTuple('Arguments', [('args', List[str]), @@ -188,7 +187,7 @@ def getargspec(func: object) -> ArgSpec: ... FullArgSpec = NamedTuple('FullArgSpec', [('args', List[str]), ('varargs', Optional[str]), ('varkw', Optional[str]), - ('defaults', tuple), + ('defaults', Tuple[Any, ...]), ('kwonlyargs', List[str]), ('kwonlydefaults', Dict[str, Any]), ('annotations', Dict[str, Any]), diff --git a/stdlib/3/ipaddress.pyi b/stdlib/3/ipaddress.pyi index c6855fe264b7..3d507f41b911 100644 --- a/stdlib/3/ipaddress.pyi +++ b/stdlib/3/ipaddress.pyi @@ -54,7 +54,7 @@ class _BaseAddress(_IPAddressBase, SupportsInt): @property def packed(self) -> bytes: ... -class _BaseNetwork(_IPAddressBase, Container, Iterable[_A], Generic[_A]): +class _BaseNetwork(_IPAddressBase, Container[_A], Iterable[_A], Generic[_A]): network_address: _A netmask: _A def __init__(self, address: object, strict: bool = ...) -> None: ... diff --git a/stdlib/3/json/__init__.pyi b/stdlib/3/json/__init__.pyi index e60c4727dc51..2f6374e3ba6a 100644 --- a/stdlib/3/json/__init__.pyi +++ b/stdlib/3/json/__init__.pyi @@ -37,7 +37,7 @@ else: def loads(s: _LoadsString, encoding: Any = ..., # ignored and deprecated cls: Optional[Type[JSONDecoder]] = ..., - object_hook: Optional[Callable[[Dict], Any]] = ..., + object_hook: Optional[Callable[[Dict[Any, Any]], Any]] = ..., parse_float: Optional[Callable[[str], Any]] = ..., parse_int: Optional[Callable[[str], Any]] = ..., parse_constant: Optional[Callable[[str], Any]] = ..., @@ -49,7 +49,7 @@ class _Reader(Protocol): def load(fp: _Reader, cls: Optional[Type[JSONDecoder]] = ..., - object_hook: Optional[Callable[[Dict], Any]] = ..., + object_hook: Optional[Callable[[Dict[Any, Any]], Any]] = ..., parse_float: Optional[Callable[[str], Any]] = ..., parse_int: Optional[Callable[[str], Any]] = ..., parse_constant: Optional[Callable[[str], Any]] = ..., diff --git a/stdlib/3/json/encoder.pyi b/stdlib/3/json/encoder.pyi index e35f344b2f40..63f5ffebe7df 100644 --- a/stdlib/3/json/encoder.pyi +++ b/stdlib/3/json/encoder.pyi @@ -14,7 +14,7 @@ class JSONEncoder: def __init__(self, skipkeys: bool = ..., ensure_ascii: bool = ..., check_circular: bool = ..., allow_nan: bool = ..., sort_keys: bool = ..., indent: Optional[int] = ..., separators: Optional[Tuple[str, str]] = ..., - default: Optional[Callable] = ...) -> None: ... + default: Optional[Callable[..., Any]] = ...) -> None: ... def default(self, o: Any) -> Any: ... def encode(self, o: Any) -> str: ... diff --git a/stdlib/3/multiprocessing/__init__.pyi b/stdlib/3/multiprocessing/__init__.pyi index fb514266bd6b..e2513f3bd75e 100644 --- a/stdlib/3/multiprocessing/__init__.pyi +++ b/stdlib/3/multiprocessing/__init__.pyi @@ -26,7 +26,7 @@ import sys # Sychronization primitives _LockLike = Union[synchronize.Lock, synchronize.RLock] def Barrier(parties: int, - action: Optional[Callable] = ..., + action: Optional[Callable[..., Any]] = ..., timeout: Optional[float] = ...) -> synchronize.Barrier: ... def BoundedSemaphore(value: int = ...) -> synchronize.BoundedSemaphore: ... def Condition(lock: Optional[_LockLike] = ...) -> synchronize.Condition: ... @@ -52,7 +52,7 @@ class Process(): # TODO: set type of group to None def __init__(self, group: Any = ..., - target: Optional[Callable] = ..., + target: Optional[Callable[..., Any]] = ..., name: Optional[str] = ..., args: Iterable[Any] = ..., kwargs: Mapping[Any, Any] = ..., diff --git a/stdlib/3/multiprocessing/context.pyi b/stdlib/3/multiprocessing/context.pyi index dada9b3ea93a..2cdeb07d14cc 100644 --- a/stdlib/3/multiprocessing/context.pyi +++ b/stdlib/3/multiprocessing/context.pyi @@ -41,7 +41,7 @@ class BaseContext(object): def Barrier(self, parties: int, - action: Optional[Callable] = ..., + action: Optional[Callable[..., Any]] = ..., timeout: Optional[float] = ...) -> synchronize.Barrier: ... def BoundedSemaphore(self, value: int = ...) -> synchronize.BoundedSemaphore: ... @@ -52,9 +52,9 @@ class BaseContext(object): def RLock(self) -> synchronize.RLock: ... def Semaphore(self, value: int = ...) -> synchronize.Semaphore: ... - def Queue(self, maxsize: int = ...) -> queues.Queue: ... - def JoinableQueue(self, maxsize: int = ...) -> queues.JoinableQueue: ... - def SimpleQueue(self) -> queues.SimpleQueue: ... + def Queue(self, maxsize: int = ...) -> queues.Queue[Any]: ... + def JoinableQueue(self, maxsize: int = ...) -> queues.JoinableQueue[Any]: ... + def SimpleQueue(self) -> queues.SimpleQueue[Any]: ... def Pool( self, processes: Optional[int] = ..., @@ -65,7 +65,7 @@ class BaseContext(object): def Process( self, group: Any = ..., - target: Optional[Callable] = ..., + target: Optional[Callable[..., Any]] = ..., name: Optional[str] = ..., args: Iterable[Any] = ..., kwargs: Mapping[Any, Any] = ..., diff --git a/stdlib/3/multiprocessing/dummy/__init__.pyi b/stdlib/3/multiprocessing/dummy/__init__.pyi index c169d2d0e853..2a995cda633a 100644 --- a/stdlib/3/multiprocessing/dummy/__init__.pyi +++ b/stdlib/3/multiprocessing/dummy/__init__.pyi @@ -14,7 +14,7 @@ JoinableQueue = Queue class DummyProcess(threading.Thread): - _children: weakref.WeakKeyDictionary + _children: weakref.WeakKeyDictionary[Any, Any] _parent: threading.Thread _pid: None _start_called: int @@ -33,10 +33,10 @@ class Value(object): def __init__(self, typecode, value, lock=...) -> None: ... -def Array(typecode, sequence, lock=...) -> array.array: ... +def Array(typecode, sequence, lock=...) -> array.array[Any]: ... def Manager() -> Any: ... def Pool(processes=..., initializer=..., initargs=...) -> Any: ... -def active_children() -> List: ... +def active_children() -> List[Any]: ... def current_process() -> threading.Thread: ... def freeze_support() -> None: ... def shutdown() -> None: ... diff --git a/stdlib/3/multiprocessing/dummy/connection.pyi b/stdlib/3/multiprocessing/dummy/connection.pyi index 3baaf286f24a..537750e19f3b 100644 --- a/stdlib/3/multiprocessing/dummy/connection.pyi +++ b/stdlib/3/multiprocessing/dummy/connection.pyi @@ -21,9 +21,9 @@ class Connection(object): def poll(self, timeout: float = ...) -> bool: ... class Listener(object): - _backlog_queue: Optional[Queue] + _backlog_queue: Optional[Queue[Any]] @property - def address(self) -> Optional[Queue]: ... + def address(self) -> Optional[Queue[Any]]: ... def __enter__(self: _TListener) -> _TListener: ... def __exit__(self, exc_type, exc_value, exc_tb) -> None: ... def __init__(self, address=..., family=..., backlog=...) -> None: ... diff --git a/stdlib/3/multiprocessing/managers.pyi b/stdlib/3/multiprocessing/managers.pyi index 7c19b1d2035f..7522d0ae437f 100644 --- a/stdlib/3/multiprocessing/managers.pyi +++ b/stdlib/3/multiprocessing/managers.pyi @@ -28,7 +28,7 @@ class BaseManager(ContextManager[BaseManager]): address: Union[str, Tuple[str, int]] def connect(self) -> None: ... @classmethod - def register(cls, typeid: str, callable: Optional[Callable] = ..., + def register(cls, typeid: str, callable: Optional[Callable[..., Any]] = ..., proxytype: Any = ..., exposed: Optional[Sequence[str]] = ..., method_to_typeid: Optional[Mapping[str, str]] = ..., @@ -43,7 +43,7 @@ class SyncManager(BaseManager, ContextManager[SyncManager]): def Event(self) -> threading.Event: ... def Lock(self) -> threading.Lock: ... def Namespace(self) -> _Namespace: ... - def Queue(self, maxsize: int = ...) -> queue.Queue: ... + def Queue(self, maxsize: int = ...) -> queue.Queue[Any]: ... def RLock(self) -> threading.RLock: ... def Semaphore(self, value: Any = ...) -> threading.Semaphore: ... def Array(self, typecode: Any, sequence: Sequence[_T]) -> Sequence[_T]: ... diff --git a/stdlib/3/multiprocessing/pool.pyi b/stdlib/3/multiprocessing/pool.pyi index fe1045d0a4d8..3782a3f1dc4b 100644 --- a/stdlib/3/multiprocessing/pool.pyi +++ b/stdlib/3/multiprocessing/pool.pyi @@ -19,14 +19,12 @@ AsyncResult = ApplyResult class MapResult(ApplyResult[List[_T]]): ... -_IMIT = TypeVar('_IMIT', bound=IMapIterator) - class IMapIterator(Iterator[_T]): - def __iter__(self: _IMIT) -> _IMIT: ... + def __iter__(self: _S) -> _S: ... def next(self, timeout: Optional[float] = ...) -> _T: ... def __next__(self, timeout: Optional[float] = ...) -> _T: ... -class IMapUnorderedIterator(IMapIterator): ... +class IMapUnorderedIterator(IMapIterator[_T]): ... class Pool(ContextManager[Pool]): def __init__(self, processes: Optional[int] = ..., diff --git a/stdlib/3/multiprocessing/synchronize.pyi b/stdlib/3/multiprocessing/synchronize.pyi index 9b226810e628..224485b317ba 100644 --- a/stdlib/3/multiprocessing/synchronize.pyi +++ b/stdlib/3/multiprocessing/synchronize.pyi @@ -1,4 +1,4 @@ -from typing import Callable, ContextManager, Optional, Union +from typing import Any, Callable, ContextManager, Optional, Union from multiprocessing.context import BaseContext import threading @@ -9,7 +9,7 @@ _LockLike = Union[Lock, RLock] class Barrier(threading.Barrier): def __init__(self, parties: int, - action: Optional[Callable] = ..., + action: Optional[Callable[..., Any]] = ..., timeout: Optional[float] = ..., * ctx: BaseContext) -> None: ... diff --git a/stdlib/3/os/__init__.pyi b/stdlib/3/os/__init__.pyi index 458fc75c1952..085000a0922f 100644 --- a/stdlib/3/os/__init__.pyi +++ b/stdlib/3/os/__init__.pyi @@ -282,12 +282,12 @@ if sys.platform != 'win32': # ----- os function stubs ----- if sys.version_info >= (3, 6): - def fsencode(filename: Union[str, bytes, PathLike]) -> bytes: ... + def fsencode(filename: Union[str, bytes, PathLike[Any]]) -> bytes: ... else: def fsencode(filename: Union[str, bytes]) -> bytes: ... if sys.version_info >= (3, 6): - def fsdecode(filename: Union[str, bytes, PathLike]) -> str: ... + def fsdecode(filename: Union[str, bytes, PathLike[Any]]) -> str: ... else: def fsdecode(filename: Union[str, bytes]) -> str: ... @@ -297,7 +297,7 @@ if sys.version_info >= (3, 6): @overload def fspath(path: bytes) -> bytes: ... @overload - def fspath(path: PathLike) -> Any: ... + def fspath(path: PathLike[Any]) -> Any: ... def get_exec_path(env: Optional[Mapping[str, str]] = ...) -> List[str]: ... # NOTE: get_exec_path(): returns List[bytes] when env not None @@ -506,32 +506,34 @@ def utime( follow_symlinks: bool = ..., ) -> None: ... +_OnError = Callable[[OSError], Any] + if sys.version_info >= (3, 6): def walk(top: Union[AnyStr, PathLike[AnyStr]], topdown: bool = ..., - onerror: Optional[Callable[[OSError], Any]] = ..., + onerror: Optional[_OnError] = ..., followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr], List[AnyStr]]]: ... else: - def walk(top: AnyStr, topdown: bool = ..., onerror: Optional[Callable[[OSError], Any]] = ..., + def walk(top: AnyStr, topdown: bool = ..., onerror: Optional[_OnError] = ..., followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr], List[AnyStr]]]: ... if sys.platform != 'win32': if sys.version_info >= (3, 7): @overload def fwalk(top: Union[str, PathLike[str]] = ..., topdown: bool = ..., - onerror: Optional[Callable] = ..., *, follow_symlinks: bool = ..., + onerror: Optional[_OnError] = ..., *, follow_symlinks: bool = ..., dir_fd: Optional[int] = ...) -> Iterator[Tuple[str, List[str], List[str], int]]: ... @overload def fwalk(top: bytes, topdown: bool = ..., - onerror: Optional[Callable] = ..., *, follow_symlinks: bool = ..., + onerror: Optional[_OnError] = ..., *, follow_symlinks: bool = ..., dir_fd: Optional[int] = ...) -> Iterator[Tuple[bytes, List[bytes], List[bytes], int]]: ... elif sys.version_info >= (3, 6): def fwalk(top: Union[str, PathLike[str]] = ..., topdown: bool = ..., - onerror: Optional[Callable] = ..., *, follow_symlinks: bool = ..., + onerror: Optional[_OnError] = ..., *, follow_symlinks: bool = ..., dir_fd: Optional[int] = ...) -> Iterator[Tuple[str, List[str], List[str], int]]: ... else: def fwalk(top: str = ..., topdown: bool = ..., - onerror: Optional[Callable] = ..., *, follow_symlinks: bool = ..., + onerror: Optional[_OnError] = ..., *, follow_symlinks: bool = ..., dir_fd: Optional[int] = ...) -> Iterator[Tuple[str, List[str], List[str], int]]: ... def getxattr(path: _FdOrPathType, attribute: _PathType, *, follow_symlinks: bool = ...) -> bytes: ... # Linux only def listxattr(path: _FdOrPathType, *, follow_symlinks: bool = ...) -> List[str]: ... # Linux only diff --git a/stdlib/3/queue.pyi b/stdlib/3/queue.pyi index f6bafc04f0b7..9647faf4c0d3 100644 --- a/stdlib/3/queue.pyi +++ b/stdlib/3/queue.pyi @@ -2,9 +2,8 @@ # NOTE: These are incomplete! -from collections import deque from threading import Condition, Lock -from typing import Any, TypeVar, Generic, Optional +from typing import Any, Deque, TypeVar, Generic, Optional import sys _T = TypeVar('_T') @@ -21,7 +20,7 @@ class Queue(Generic[_T]): all_tasks_done: Condition # undocumented unfinished_tasks: int # undocumented - queue: deque # undocumented + queue: Deque[Any] # undocumented def __init__(self, maxsize: int = ...) -> None: ... def _init(self, maxsize: int) -> None: ... def empty(self) -> bool: ... diff --git a/stdlib/3/random.pyi b/stdlib/3/random.pyi index 35ee63488bf7..7fa0698a0a0e 100644 --- a/stdlib/3/random.pyi +++ b/stdlib/3/random.pyi @@ -8,17 +8,15 @@ import _random import sys -from typing import ( - Any, TypeVar, Sequence, List, Callable, AbstractSet, Union, Optional -) +from typing import Any, TypeVar, Sequence, List, Callable, AbstractSet, Union, Optional, Tuple _T = TypeVar('_T') class Random(_random.Random): def __init__(self, x: Any = ...) -> None: ... def seed(self, a: Any = ..., version: int = ...) -> None: ... - def getstate(self) -> tuple: ... - def setstate(self, state: tuple) -> None: ... + def getstate(self) -> Tuple[Any, ...]: ... + def setstate(self, state: Tuple[Any, ...]) -> None: ... def getrandbits(self, k: int) -> int: ... def randrange(self, start: int, stop: Union[int, None] = ..., step: int = ...) -> int: ... def randint(self, a: int, b: int) -> int: ... diff --git a/stdlib/3/reprlib.pyi b/stdlib/3/reprlib.pyi index 462251875f39..7ff879bc7704 100644 --- a/stdlib/3/reprlib.pyi +++ b/stdlib/3/reprlib.pyi @@ -24,7 +24,7 @@ class Repr: def repr1(self, x: Any, level: int) -> str: ... def repr_tuple(self, x: Tuple[Any, ...], level: int) -> str: ... def repr_list(self, x: List[Any], level: int) -> str: ... - def repr_array(self, x: array, level: int) -> str: ... + def repr_array(self, x: array[Any], level: int) -> str: ... def repr_set(self, x: Set[Any], level: int) -> str: ... def repr_frozenset(self, x: FrozenSet[Any], level: int) -> str: ... def repr_deque(self, x: Deque[Any], level: int) -> str: ... diff --git a/stdlib/3/shelve.pyi b/stdlib/3/shelve.pyi index 4a339692ce00..97a045e0e849 100644 --- a/stdlib/3/shelve.pyi +++ b/stdlib/3/shelve.pyi @@ -2,7 +2,7 @@ from typing import Any, Dict, Iterator, Optional, Tuple import collections -class Shelf(collections.MutableMapping): +class Shelf(collections.MutableMapping[Any, Any]): def __init__(self, dict: Dict[bytes, Any], protocol: Optional[int] = ..., writeback: bool = ..., keyencoding: str = ...) -> None: ... def __iter__(self) -> Iterator[str]: ... def __len__(self) -> int: ... diff --git a/stdlib/3/sre_parse.pyi b/stdlib/3/sre_parse.pyi index 93b3c1dd7dab..8757af795665 100644 --- a/stdlib/3/sre_parse.pyi +++ b/stdlib/3/sre_parse.pyi @@ -77,5 +77,5 @@ class Tokenizer: def fix_flags(src: Union[str, bytes], flag: int) -> int: ... def parse(str: str, flags: int = ..., pattern: Pattern = ...) -> SubPattern: ... _TemplateType = Tuple[List[Tuple[int, int]], List[str]] -def parse_template(source: str, pattern: _Pattern) -> _TemplateType: ... -def expand_template(template: _TemplateType, match: Match) -> str: ... +def parse_template(source: str, pattern: _Pattern[Any]) -> _TemplateType: ... +def expand_template(template: _TemplateType, match: Match[Any]) -> str: ... diff --git a/stdlib/3/subprocess.pyi b/stdlib/3/subprocess.pyi index c3126dd62fe6..8bc2e807e571 100644 --- a/stdlib/3/subprocess.pyi +++ b/stdlib/3/subprocess.pyi @@ -40,6 +40,7 @@ else: _CMD = Union[_TXT, Sequence[_PATH]] _ENV = Union[Mapping[bytes, _TXT], Mapping[Text, _TXT]] +_S = TypeVar('_S') _T = TypeVar('_T') class CompletedProcess(Generic[_T]): @@ -1169,7 +1170,7 @@ class Popen(Generic[AnyStr]): def send_signal(self, signal: int) -> None: ... def terminate(self) -> None: ... def kill(self) -> None: ... - def __enter__(self) -> Popen: ... + def __enter__(self: _S) -> _S: ... def __exit__(self, type: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) -> None: ... # The result really is always a str. diff --git a/stdlib/3/tempfile.pyi b/stdlib/3/tempfile.pyi index 5baf9abf385b..5d66a47a1b43 100644 --- a/stdlib/3/tempfile.pyi +++ b/stdlib/3/tempfile.pyi @@ -18,6 +18,7 @@ TMP_MAX: int tempdir: Optional[str] template: str +_S = TypeVar("_S") _T = TypeVar("_T") # for pytype, define typevar in same file as alias if sys.version_info >= (3, 6): _DirT = Union[_T, os.PathLike[_T]] @@ -98,7 +99,7 @@ class SpooledTemporaryFile(IO[AnyStr]): prefix: Optional[str] = ..., dir: Optional[str] = ... ) -> None: ... def rollover(self) -> None: ... - def __enter__(self) -> SpooledTemporaryFile: ... + def __enter__(self: _S) -> _S: ... def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]) -> Optional[bool]: ... diff --git a/stdlib/3/tokenize.pyi b/stdlib/3/tokenize.pyi index 9b6b50d2ee3c..b3c5fd9641b6 100644 --- a/stdlib/3/tokenize.pyi +++ b/stdlib/3/tokenize.pyi @@ -45,7 +45,7 @@ def generate_tokens(readline: Callable[[], str]) -> Generator[TokenInfo, None, N if sys.version_info >= (3, 6): from os import PathLike - def open(filename: Union[str, bytes, int, PathLike]) -> TextIO: ... + def open(filename: Union[str, bytes, int, PathLike[Any]]) -> TextIO: ... else: def open(filename: Union[str, bytes, int]) -> TextIO: ... diff --git a/stdlib/3/types.pyi b/stdlib/3/types.pyi index 5d0acc7dd24c..61f87832ad9e 100644 --- a/stdlib/3/types.pyi +++ b/stdlib/3/types.pyi @@ -147,7 +147,7 @@ class MethodType: __self__: object __name__: str __qualname__: str - def __init__(self, func: Callable, obj: object) -> None: ... + def __init__(self, func: Callable[..., Any], obj: object) -> None: ... def __call__(self, *args: Any, **kwargs: Any) -> Any: ... class BuiltinFunctionType: __self__: Union[object, ModuleType] diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index 3d36ce2736a7..4aa4988bd25f 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -75,7 +75,7 @@ _KT_co = TypeVar('_KT_co', covariant=True) # Key type covariant containers. _VT_co = TypeVar('_VT_co', covariant=True) # Value type covariant containers. _T_contra = TypeVar('_T_contra', contravariant=True) # Ditto contravariant. _TC = TypeVar('_TC', bound=Type[object]) -_C = TypeVar("_C", bound=Callable) +_C = TypeVar("_C", bound=Callable[..., Any]) def runtime_checkable(cls: _TC) -> _TC: ... @@ -166,7 +166,7 @@ class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]): @property def gi_running(self) -> bool: ... @property - def gi_yieldfrom(self) -> Optional[Generator]: ... + def gi_yieldfrom(self) -> Optional[Generator[Any, Any, Any]]: ... @runtime_checkable class Awaitable(Protocol[_T_co]): @@ -581,8 +581,9 @@ class Pattern(Generic[AnyStr]): # Functions -def get_type_hints(obj: Callable, globalns: Optional[dict[str, Any]] = ..., - localns: Optional[dict[str, Any]] = ...) -> dict[str, Any]: ... +def get_type_hints( + obj: Callable[..., Any], globalns: Optional[Dict[str, Any]] = ..., localns: Optional[Dict[str, Any]] = ..., +) -> Dict[str, Any]: ... @overload def cast(tp: Type[_T], obj: Any) -> _T: ... @@ -592,7 +593,7 @@ def cast(tp: str, obj: Any) -> Any: ... # Type constructors # NamedTuple is special-cased in the type checker -class NamedTuple(tuple): +class NamedTuple(Tuple[Any, ...]): _field_types: collections.OrderedDict[str, Type[Any]] _field_defaults: Dict[str, Any] = ... _fields: Tuple[str, ...] diff --git a/stdlib/3/unittest/mock.pyi b/stdlib/3/unittest/mock.pyi index 8b20ea60217d..b4c4ce38aab9 100644 --- a/stdlib/3/unittest/mock.pyi +++ b/stdlib/3/unittest/mock.pyi @@ -1,7 +1,9 @@ # Stubs for mock import sys -from typing import Any, Optional, Text, Type +from typing import Any, List, Optional, Text, Tuple, Type, TypeVar + +_T = TypeVar("_T") FILTER_DIR: Any @@ -18,7 +20,7 @@ class _Sentinel: sentinel: Any DEFAULT: Any -class _CallList(list): +class _CallList(List[_T]): def __contains__(self, value: Any) -> bool: ... class _MockIter: @@ -111,7 +113,7 @@ class _ANY: ANY: Any -class _Call(tuple): +class _Call(Tuple[Any, ...]): def __new__(cls, value: Any = ..., name: Optional[Any] = ..., parent: Optional[Any] = ..., two: bool = ..., from_kall: bool = ...) -> Any: ... name: Any parent: Any diff --git a/stdlib/3/urllib/parse.pyi b/stdlib/3/urllib/parse.pyi index b835119ec890..952d3cf9e346 100644 --- a/stdlib/3/urllib/parse.pyi +++ b/stdlib/3/urllib/parse.pyi @@ -35,7 +35,7 @@ class _NetlocResultMixinStr(_NetlocResultMixinBase[str], _ResultMixinStr): ... class _NetlocResultMixinBytes(_NetlocResultMixinBase[bytes], _ResultMixinBytes): ... -class _DefragResultBase(tuple, Generic[AnyStr]): +class _DefragResultBase(Tuple[Any, ...], Generic[AnyStr]): url: AnyStr fragment: AnyStr diff --git a/stdlib/3/urllib/request.pyi b/stdlib/3/urllib/request.pyi index 63152d445448..a18210a5971d 100644 --- a/stdlib/3/urllib/request.pyi +++ b/stdlib/3/urllib/request.pyi @@ -202,7 +202,7 @@ class HTTPErrorProcessor(BaseHandler): def https_response(self, request, response) -> _UrlopenRet: ... if sys.version_info >= (3, 6): - def urlretrieve(url: str, filename: Optional[Union[str, os.PathLike]] = ..., + def urlretrieve(url: str, filename: Optional[Union[str, os.PathLike[Any]]] = ..., reporthook: Optional[Callable[[int, int, int], None]] = ..., data: Optional[bytes] = ...) -> Tuple[str, HTTPMessage]: ... else: diff --git a/tests/mypy_test.py b/tests/mypy_test.py index 568f072b169a..cba411abb8ce 100755 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -132,6 +132,7 @@ def main(): flags.append('--no-site-packages') flags.append('--show-traceback') flags.append('--no-implicit-optional') + flags.append('--disallow-any-generics') if args.warn_unused_ignores: flags.append('--warn-unused-ignores') sys.argv = ['mypy'] + flags + files diff --git a/third_party/2/concurrent/futures/_base.pyi b/third_party/2/concurrent/futures/_base.pyi index 6d454fbe8388..00ff41d76959 100644 --- a/third_party/2/concurrent/futures/_base.pyi +++ b/third_party/2/concurrent/futures/_base.pyi @@ -62,25 +62,25 @@ def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: class _Waiter: event: threading.Event - finished_futures: List[Future] + finished_futures: List[Future[Any]] def __init__(self) -> None: ... - def add_result(self, future: Future) -> None: ... - def add_exception(self, future: Future) -> None: ... - def add_cancelled(self, future: Future) -> None: ... + def add_result(self, future: Future[Any]) -> None: ... + def add_exception(self, future: Future[Any]) -> None: ... + def add_cancelled(self, future: Future[Any]) -> None: ... class _AsCompletedWaiter(_Waiter): lock: threading.Lock def __init__(self) -> None: ... - def add_result(self, future: Future) -> None: ... - def add_exception(self, future: Future) -> None: ... - def add_cancelled(self, future: Future) -> None: ... + def add_result(self, future: Future[Any]) -> None: ... + def add_exception(self, future: Future[Any]) -> None: ... + def add_cancelled(self, future: Future[Any]) -> None: ... class _FirstCompletedWaiter(_Waiter): - def add_result(self, future: Future) -> None: ... - def add_exception(self, future: Future) -> None: ... - def add_cancelled(self, future: Future) -> None: ... + def add_result(self, future: Future[Any]) -> None: ... + def add_exception(self, future: Future[Any]) -> None: ... + def add_cancelled(self, future: Future[Any]) -> None: ... class _AllCompletedWaiter(_Waiter): @@ -88,13 +88,13 @@ class _AllCompletedWaiter(_Waiter): stop_on_exception: bool lock: threading.Lock def __init__(self, num_pending_calls: int, stop_on_exception: bool) -> None: ... - def add_result(self, future: Future) -> None: ... - def add_exception(self, future: Future) -> None: ... - def add_cancelled(self, future: Future) -> None: ... + def add_result(self, future: Future[Any]) -> None: ... + def add_exception(self, future: Future[Any]) -> None: ... + def add_cancelled(self, future: Future[Any]) -> None: ... class _AcquireFutures: - futures: Iterable[Future] - def __init__(self, futures: Iterable[Future]) -> None: ... + futures: Iterable[Future[Any]] + def __init__(self, futures: Iterable[Future[Any]]) -> None: ... def __enter__(self) -> None: ... def __exit__(self, *args: Any) -> None: ... diff --git a/third_party/2/concurrent/futures/thread.pyi b/third_party/2/concurrent/futures/thread.pyi index c4f895d7a543..82c8ddd03d94 100644 --- a/third_party/2/concurrent/futures/thread.pyi +++ b/third_party/2/concurrent/futures/thread.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Optional, Tuple, TypeVar, Generic +from typing import Any, Callable, Iterable, Mapping, Optional, Tuple, TypeVar, Generic from ._base import Executor, Future import sys @@ -22,10 +22,9 @@ class ThreadPoolExecutor(Executor): class _WorkItem(Generic[_S]): - future: Future - fn: Callable[[Future[_S]], Any] - args: Any - kwargs: Any - def __init__(self, future: Future, fn: Callable[[Future[_S]], Any], args: Any, - kwargs: Any) -> None: ... + future: Future[_S] + fn: Callable[..., _S] + args: Iterable[Any] + kwargs: Mapping[str, Any] + def __init__(self, future: Future[_S], fn: Callable[..., _S], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ... def run(self) -> None: ... diff --git a/third_party/2and3/boto/utils.pyi b/third_party/2and3/boto/utils.pyi index efe556193c05..7c927d8356ce 100644 --- a/third_party/2and3/boto/utils.pyi +++ b/third_party/2and3/boto/utils.pyi @@ -37,7 +37,7 @@ if sys.version_info >= (3,): else: # TODO move _StringIO definition into boto.compat once stubs exist and rename to StringIO import StringIO - _StringIO = StringIO.StringIO + _StringIO = StringIO.StringIO[Any] from hashlib import _hash _HashType = _hash diff --git a/third_party/2and3/mock.pyi b/third_party/2and3/mock.pyi index 8b20ea60217d..b4c4ce38aab9 100644 --- a/third_party/2and3/mock.pyi +++ b/third_party/2and3/mock.pyi @@ -1,7 +1,9 @@ # Stubs for mock import sys -from typing import Any, Optional, Text, Type +from typing import Any, List, Optional, Text, Tuple, Type, TypeVar + +_T = TypeVar("_T") FILTER_DIR: Any @@ -18,7 +20,7 @@ class _Sentinel: sentinel: Any DEFAULT: Any -class _CallList(list): +class _CallList(List[_T]): def __contains__(self, value: Any) -> bool: ... class _MockIter: @@ -111,7 +113,7 @@ class _ANY: ANY: Any -class _Call(tuple): +class _Call(Tuple[Any, ...]): def __new__(cls, value: Any = ..., name: Optional[Any] = ..., parent: Optional[Any] = ..., two: bool = ..., from_kall: bool = ...) -> Any: ... name: Any parent: Any