Skip to content

Enable --disallow-any-generics for stubs #3288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions stdlib/2/ConfigParser.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: ...
6 changes: 3 additions & 3 deletions stdlib/2/Cookie.pyi
Original file line number Diff line number Diff line change
@@ -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): ...
Expand All @@ -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] = ...): ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/2/Queue.pyi
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -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: ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/2/SimpleHTTPServer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/2/UserList.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Expand All @@ -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: ...
2 changes: 1 addition & 1 deletion stdlib/2/__builtin__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
19 changes: 10 additions & 9 deletions stdlib/2/_collections.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/2/_hotshot.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
25 changes: 14 additions & 11 deletions stdlib/2/_io.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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[].
Expand Down Expand Up @@ -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: ...
Expand All @@ -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[].
Expand All @@ -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 = ...,
Expand Down
16 changes: 3 additions & 13 deletions stdlib/2/_json.pyi
Original file line number Diff line number Diff line change
@@ -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): ...
18 changes: 9 additions & 9 deletions stdlib/2/_socket.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -253,34 +253,34 @@ 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:
raise error
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: ...
Expand Down
8 changes: 4 additions & 4 deletions stdlib/2/_sre.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...,
Expand Down
19 changes: 12 additions & 7 deletions stdlib/2/_warnings.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
6 changes: 3 additions & 3 deletions stdlib/2/abc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
16 changes: 5 additions & 11 deletions stdlib/2/collections.pyi
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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] = ...,
Expand Down Expand Up @@ -56,16 +56,14 @@ 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: ...
@overload
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
Expand Down Expand Up @@ -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
Expand All @@ -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: ...
15 changes: 12 additions & 3 deletions stdlib/2/compileall.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Loading