Skip to content

Commit c32e1e2

Browse files
srittauJelleZijlstra
authored andcommitted
Enable --disallow-any-generics for stubs (#3288)
1 parent 23b3533 commit c32e1e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+386
-329
lines changed

stdlib/2/ConfigParser.pyi

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class _Readable(Protocol):
5555

5656
class RawConfigParser:
5757
_dict: Any
58-
_sections: dict
59-
_defaults: dict
58+
_sections: Dict[Any, Any]
59+
_defaults: Dict[Any, Any]
6060
_optcre: Any
6161
SECTCRE: Any
6262
OPTCRE: Any
@@ -86,12 +86,14 @@ class RawConfigParser:
8686

8787
class ConfigParser(RawConfigParser):
8888
_KEYCRE: Any
89-
def get(self, section: str, option: str, raw: bool = ..., vars: Optional[dict] = ...) -> Any: ...
90-
def items(self, section: str, raw: bool = ..., vars: Optional[dict] = ...) -> List[Tuple[str, Any]]: ...
89+
def get(self, section: str, option: str, raw: bool = ..., vars: Optional[Dict[Any, Any]] = ...) -> Any: ...
90+
def items(self, section: str, raw: bool = ..., vars: Optional[Dict[Any, Any]] = ...) -> List[Tuple[str, Any]]: ...
9191
def _interpolate(self, section: str, option: str, rawval: Any, vars: Any) -> str: ...
9292
def _interpolation_replace(self, match: Any) -> str: ...
9393

9494
class SafeConfigParser(ConfigParser):
9595
_interpvar_re: Any
9696
def _interpolate(self, section: str, option: str, rawval: Any, vars: Any) -> str: ...
97-
def _interpolate_some(self, option: str, accum: list, rest: str, section: str, map: dict, depth: int) -> None: ...
97+
def _interpolate_some(
98+
self, option: str, accum: List[Any], rest: str, section: str, map: Dict[Any, Any], depth: int,
99+
) -> None: ...

stdlib/2/Cookie.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from typing import Any, Optional
1+
from typing import Any, Dict, Optional
22

33
class CookieError(Exception): ...
44

5-
class Morsel(dict):
5+
class Morsel(Dict[Any, Any]):
66
key: Any
77
def __init__(self): ...
88
def __setitem__(self, K, V): ...
@@ -14,7 +14,7 @@ class Morsel(dict):
1414
def js_output(self, attrs: Optional[Any] = ...): ...
1515
def OutputString(self, attrs: Optional[Any] = ...): ...
1616

17-
class BaseCookie(dict):
17+
class BaseCookie(Dict[Any, Any]):
1818
def value_decode(self, val): ...
1919
def value_encode(self, val): ...
2020
def __init__(self, input: Optional[Any] = ...): ...

stdlib/2/Queue.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Stubs for Queue (Python 2)
22

33
from collections import deque
4-
from typing import Any, TypeVar, Generic, Optional
4+
from typing import Any, Deque, TypeVar, Generic, Optional
55

66
_T = TypeVar('_T')
77

@@ -15,7 +15,7 @@ class Queue(Generic[_T]):
1515
not_full: Any
1616
all_tasks_done: Any
1717
unfinished_tasks: Any
18-
queue: deque # undocumented
18+
queue: Deque[Any] # undocumented
1919
def __init__(self, maxsize: int = ...) -> None: ...
2020
def task_done(self) -> None: ...
2121
def join(self) -> None: ...

stdlib/2/SimpleHTTPServer.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
99
def do_GET(self) -> None: ...
1010
def do_HEAD(self) -> None: ...
1111
def send_head(self) -> Optional[IO[str]]: ...
12-
def list_directory(self, path: Union[str, unicode]) -> Optional[StringIO]: ...
12+
def list_directory(self, path: Union[str, unicode]) -> Optional[StringIO[Any]]: ...
1313
def translate_path(self, path: AnyStr) -> AnyStr: ...
1414
def copyfile(self, source: IO[AnyStr], outputfile: IO[AnyStr]): ...
1515
def guess_type(self, path: Union[str, unicode]) -> str: ...

stdlib/2/UserList.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Iterable, MutableSequence, TypeVar, Union, overload
22

33
_T = TypeVar("_T")
4-
_ULT = TypeVar("_ULT", bound=UserList)
4+
_S = TypeVar("_S")
55

66
class UserList(MutableSequence[_T]):
77
def insert(self, index: int, object: _T) -> None: ...
@@ -14,5 +14,5 @@ class UserList(MutableSequence[_T]):
1414
@overload
1515
def __getitem__(self, i: int) -> _T: ...
1616
@overload
17-
def __getitem__(self: _ULT, s: slice) -> _ULT: ...
17+
def __getitem__(self: _S, s: slice) -> _S: ...
1818
def sort(self) -> None: ...

stdlib/2/__builtin__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ class tuple(Sequence[_T_co], Generic[_T_co]):
870870
@overload
871871
def __add__(self, x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ...
872872
@overload
873-
def __add__(self, x: tuple) -> tuple: ...
873+
def __add__(self, x: Tuple[Any, ...]) -> Tuple[Any, ...]: ...
874874
def __mul__(self, n: int) -> Tuple[_T_co, ...]: ...
875875
def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ...
876876
def count(self, x: Any) -> int: ...

stdlib/2/_collections.pyi

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
"""Stub file for the '_collections' module."""
22

3-
from typing import Any, Generic, Iterator, TypeVar, Optional, Union
4-
5-
class defaultdict(dict):
6-
default_factory: None
7-
def __init__(self, default: Any = ..., init: Any = ...) -> None: ...
8-
def __missing__(self, key) -> Any:
9-
raise KeyError()
10-
def __copy__(self) -> defaultdict: ...
11-
def copy(self) -> defaultdict: ...
3+
from typing import Any, Callable, Dict, Generic, Iterator, TypeVar, Optional, Union
124

5+
_K = TypeVar("_K")
6+
_V = TypeVar("_V")
137
_T = TypeVar('_T')
148
_T2 = TypeVar('_T2')
159

10+
class defaultdict(Dict[_K, _V]):
11+
default_factory: None
12+
def __init__(self, __default_factory: Callable[[], _V] = ..., init: Any = ...) -> None: ...
13+
def __missing__(self, key: _K) -> _V: ...
14+
def __copy__(self: _T) -> _T: ...
15+
def copy(self: _T) -> _T: ...
16+
1617
class deque(Generic[_T]):
1718
maxlen: Optional[int]
1819
def __init__(self, iterable: Iterator[_T] = ..., maxlen: int = ...) -> None: ...

stdlib/2/_hotshot.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def logreader(a: str) -> LogReaderType:
1414
def profiler(a: str, *args, **kwargs) -> Any:
1515
raise IOError()
1616

17-
def resolution() -> tuple: ...
17+
def resolution() -> Tuple[Any, ...]: ...
1818

1919

2020
class LogReaderType(object):

stdlib/2/_io.pyi

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ class BufferedWriter(_BufferedIOBase):
8484

8585
class BytesIO(_BufferedIOBase):
8686
def __init__(self, initial_bytes: bytes = ...) -> None: ...
87-
def __setstate__(self, tuple) -> None: ...
88-
def __getstate__(self) -> tuple: ...
87+
def __setstate__(self, state: Tuple[Any, ...]) -> None: ...
88+
def __getstate__(self) -> Tuple[Any, ...]: ...
8989
# BytesIO does not contain a "name" field. This workaround is necessary
9090
# to allow BytesIO sub-classes to add this field, as it is defined
9191
# as a read-only property on IO[].
@@ -129,7 +129,7 @@ class _TextIOBase(TextIO):
129129
def _checkSeekable(self) -> None: ...
130130
def _checkWritable(self) -> None: ...
131131
def close(self) -> None: ...
132-
def detach(self) -> IO: ...
132+
def detach(self) -> IO[Any]: ...
133133
def fileno(self) -> int: ...
134134
def flush(self) -> None: ...
135135
def isatty(self) -> bool: ...
@@ -154,8 +154,8 @@ class StringIO(_TextIOBase):
154154
def __init__(self,
155155
initial_value: Optional[unicode] = ...,
156156
newline: Optional[unicode] = ...) -> None: ...
157-
def __setstate__(self, state: tuple) -> None: ...
158-
def __getstate__(self) -> tuple: ...
157+
def __setstate__(self, state: Tuple[Any, ...]) -> None: ...
158+
def __getstate__(self) -> Tuple[Any, ...]: ...
159159
# StringIO does not contain a "name" field. This workaround is necessary
160160
# to allow StringIO sub-classes to add this field, as it is defined
161161
# as a read-only property on IO[].
@@ -167,12 +167,15 @@ class TextIOWrapper(_TextIOBase):
167167
line_buffering: bool
168168
buffer: BinaryIO
169169
_CHUNK_SIZE: int
170-
def __init__(self, buffer: IO,
171-
encoding: Optional[Text] = ...,
172-
errors: Optional[Text] = ...,
173-
newline: Optional[Text] = ...,
174-
line_buffering: bool = ...,
175-
write_through: bool = ...) -> None: ...
170+
def __init__(
171+
self,
172+
buffer: IO[Any],
173+
encoding: Optional[Text] = ...,
174+
errors: Optional[Text] = ...,
175+
newline: Optional[Text] = ...,
176+
line_buffering: bool = ...,
177+
write_through: bool = ...,
178+
) -> None: ...
176179

177180
def open(file: Union[str, unicode, int],
178181
mode: Text = ...,

stdlib/2/_json.pyi

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
1-
"""Stub file for the '_json' module."""
2-
# This is an autogenerated file. It serves as a starting point
3-
# for a more precise manual annotation of this module.
4-
# Feel free to edit the source below, but remove this header when you do.
5-
6-
from typing import Any, List, Tuple, Dict, Generic
7-
8-
def encode_basestring_ascii(*args, **kwargs) -> str:
9-
raise TypeError()
10-
11-
def scanstring(a, b, *args, **kwargs) -> tuple:
12-
raise TypeError()
1+
from typing import Any, List, Tuple, Dict, Generic, Tuple
132

3+
def encode_basestring_ascii(*args, **kwargs) -> str: ...
4+
def scanstring(a, b, *args, **kwargs) -> Tuple[Any, ...]: ...
145

156
class Encoder(object): ...
16-
177
class Scanner(object): ...

stdlib/2/_socket.pyi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,34 +253,34 @@ class SocketType(object):
253253
timeout: float
254254

255255
def __init__(self, family: int = ..., type: int = ..., proto: int = ...) -> None: ...
256-
def accept(self) -> Tuple[SocketType, tuple]: ...
257-
def bind(self, address: tuple) -> None: ...
256+
def accept(self) -> Tuple[SocketType, Tuple[Any, ...]]: ...
257+
def bind(self, address: Tuple[Any, ...]) -> None: ...
258258
def close(self) -> None: ...
259-
def connect(self, address: tuple) -> None:
259+
def connect(self, address: Tuple[Any, ...]) -> None:
260260
raise gaierror
261261
raise timeout
262-
def connect_ex(self, address: tuple) -> int: ...
262+
def connect_ex(self, address: Tuple[Any, ...]) -> int: ...
263263
def dup(self) -> SocketType: ...
264264
def fileno(self) -> int: ...
265-
def getpeername(self) -> tuple: ...
266-
def getsockname(self) -> tuple: ...
265+
def getpeername(self) -> Tuple[Any, ...]: ...
266+
def getsockname(self) -> Tuple[Any, ...]: ...
267267
def getsockopt(self, level: int, option: int, buffersize: int = ...) -> str: ...
268268
def gettimeout(self) -> float: ...
269269
def listen(self, backlog: int) -> None:
270270
raise error
271271
def makefile(self, mode: str = ..., buffersize: int = ...) -> IO[Any]: ...
272272
def recv(self, buffersize: int, flags: int = ...) -> str: ...
273273
def recv_into(self, buffer: bytearray, nbytes: int = ..., flags: int = ...) -> int: ...
274-
def recvfrom(self, buffersize: int, flags: int = ...) -> tuple:
274+
def recvfrom(self, buffersize: int, flags: int = ...) -> Tuple[Any, ...]:
275275
raise error
276276
def recvfrom_into(self, buffer: bytearray, nbytes: int = ...,
277277
flags: int = ...) -> int: ...
278278
def send(self, data: str, flags: int = ...) -> int: ...
279279
def sendall(self, data: str, flags: int = ...) -> None: ...
280280
@overload
281-
def sendto(self, data: str, address: tuple) -> int: ...
281+
def sendto(self, data: str, address: Tuple[Any, ...]) -> int: ...
282282
@overload
283-
def sendto(self, data: str, flags: int, address: tuple) -> int: ...
283+
def sendto(self, data: str, flags: int, address: Tuple[Any, ...]) -> int: ...
284284
def setblocking(self, flag: bool) -> None: ...
285285
def setsockopt(self, level: int, option: int, value: Union[int, str]) -> None: ...
286286
def settimeout(self, value: Optional[float]) -> None: ...

stdlib/2/_sre.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ class SRE_Pattern(object):
3535
groups: int
3636
groupindex: Mapping[str, int]
3737
indexgroup: Sequence[int]
38-
def findall(self, source: str, pos: int = ..., endpos: int = ...) -> List[Union[tuple, str]]: ...
39-
def finditer(self, source: str, pos: int = ..., endpos: int = ...) -> Iterable[Union[tuple, str]]: ...
38+
def findall(self, source: str, pos: int = ..., endpos: int = ...) -> List[Union[Tuple[Any, ...], str]]: ...
39+
def finditer(self, source: str, pos: int = ..., endpos: int = ...) -> Iterable[Union[Tuple[Any, ...], str]]: ...
4040
def match(self, pattern, pos: int = ..., endpos: int = ...) -> SRE_Match: ...
4141
def scanner(self, s: str, start: int = ..., end: int = ...) -> SRE_Scanner: ...
4242
def search(self, pattern, pos: int = ..., endpos: int = ...) -> SRE_Match: ...
4343
def split(self, source: str, maxsplit: int = ...) -> List[Optional[str]]: ...
44-
def sub(self, repl: str, string: str, count: int = ...) -> tuple: ...
45-
def subn(self, repl: str, string: str, count: int = ...) -> tuple: ...
44+
def sub(self, repl: str, string: str, count: int = ...) -> Tuple[Any, ...]: ...
45+
def subn(self, repl: str, string: str, count: int = ...) -> Tuple[Any, ...]: ...
4646

4747
def compile(pattern: str, flags: int, code: List[int],
4848
groups: int = ...,

stdlib/2/_warnings.pyi

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
from typing import Any, List, Optional, Type
1+
from typing import Any, Dict, List, Optional, Tuple, Type
22

33
default_action: str
4-
filters: List[tuple]
5-
once_registry: dict
4+
filters: List[Tuple[Any, ...]]
5+
once_registry: Dict[Any, Any]
66

77
def warn(message: Warning, category: Optional[Type[Warning]] = ..., stacklevel: int = ...) -> None: ...
8-
def warn_explicit(message: Warning, category: Optional[Type[Warning]],
9-
filename: str, lineno: int,
10-
module: Any = ..., registry: dict = ...,
11-
module_globals: dict = ...) -> None: ...
8+
def warn_explicit(
9+
message: Warning,
10+
category: Optional[Type[Warning]],
11+
filename: str,
12+
lineno: int,
13+
module: Any = ...,
14+
registry: Dict[Any, Any] = ...,
15+
module_globals: Dict[Any, Any] = ...,
16+
) -> None: ...

stdlib/2/abc.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ def abstractmethod(funcobj: _FuncT) -> _FuncT: ...
1010
class ABCMeta(type):
1111
# TODO: FrozenSet
1212
__abstractmethods__: Set[Any]
13-
_abc_cache: _weakrefset.WeakSet
13+
_abc_cache: _weakrefset.WeakSet[Any]
1414
_abc_invalidation_counter: int
15-
_abc_negative_cache: _weakrefset.WeakSet
15+
_abc_negative_cache: _weakrefset.WeakSet[Any]
1616
_abc_negative_cache_version: int
17-
_abc_registry: _weakrefset.WeakSet
17+
_abc_registry: _weakrefset.WeakSet[Any]
1818
def __init__(self, name: str, bases: Tuple[type, ...], namespace: Dict[Any, Any]) -> None: ...
1919
def __instancecheck__(cls: ABCMeta, instance: Any) -> Any: ...
2020
def __subclasscheck__(cls: ABCMeta, subclass: Any) -> Any: ...

stdlib/2/collections.pyi

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# These are not exported.
2-
from typing import Dict, Generic, TypeVar, Tuple, overload, Type, Optional, List, Union, Reversible
2+
from typing import Any, Dict, Generic, TypeVar, Tuple, overload, Type, Optional, List, Union, Reversible
33

44
# These are exported.
55
from typing import (
@@ -28,7 +28,7 @@ _VT = TypeVar('_VT')
2828

2929
# namedtuple is special-cased in the type checker; the initializer is ignored.
3030
def namedtuple(typename: Union[str, unicode], field_names: Union[str, unicode, Iterable[Union[str, unicode]]],
31-
verbose: bool = ..., rename: bool = ...) -> Type[tuple]: ...
31+
verbose: bool = ..., rename: bool = ...) -> Type[Tuple[Any, ...]]: ...
3232

3333
class deque(Sized, Iterable[_T], Reversible[_T], Generic[_T]):
3434
def __init__(self, iterable: Iterable[_T] = ...,
@@ -56,16 +56,14 @@ class deque(Sized, Iterable[_T], Reversible[_T], Generic[_T]):
5656
def __reversed__(self) -> Iterator[_T]: ...
5757
def __iadd__(self: _S, iterable: Iterable[_T]) -> _S: ...
5858

59-
_CounterT = TypeVar('_CounterT', bound=Counter)
60-
6159
class Counter(Dict[_T, int], Generic[_T]):
6260
@overload
6361
def __init__(self, **kwargs: int) -> None: ...
6462
@overload
6563
def __init__(self, mapping: Mapping[_T, int]) -> None: ...
6664
@overload
6765
def __init__(self, iterable: Iterable[_T]) -> None: ...
68-
def copy(self: _CounterT) -> _CounterT: ...
66+
def copy(self: _S) -> _S: ...
6967
def elements(self) -> Iterator[_T]: ...
7068
def most_common(self, n: Optional[int] = ...) -> List[Tuple[_T, int]]: ...
7169
@overload
@@ -93,15 +91,11 @@ class Counter(Dict[_T, int], Generic[_T]):
9391
def __iand__(self, other: Counter[_T]) -> Counter[_T]: ...
9492
def __ior__(self, other: Counter[_T]) -> Counter[_T]: ...
9593

96-
_OrderedDictT = TypeVar('_OrderedDictT', bound=OrderedDict)
97-
9894
class OrderedDict(Dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):
9995
def popitem(self, last: bool = ...) -> Tuple[_KT, _VT]: ...
100-
def copy(self: _OrderedDictT) -> _OrderedDictT: ...
96+
def copy(self: _S) -> _S: ...
10197
def __reversed__(self) -> Iterator[_KT]: ...
10298

103-
_DefaultDictT = TypeVar('_DefaultDictT', bound=defaultdict)
104-
10599
class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]):
106100
default_factory: Callable[[], _VT]
107101
@overload
@@ -123,4 +117,4 @@ class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]):
123117
def __init__(self, default_factory: Optional[Callable[[], _VT]],
124118
iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
125119
def __missing__(self, key: _KT) -> _VT: ...
126-
def copy(self: _DefaultDictT) -> _DefaultDictT: ...
120+
def copy(self: _S) -> _S: ...

stdlib/2/compileall.pyi

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
# Stubs for compileall (Python 2)
22

3-
from typing import Optional, Pattern, Union
3+
from typing import Any, Optional, Pattern, Union
44

55
_Path = Union[str, bytes]
66

77
# rx can be any object with a 'search' method; once we have Protocols we can change the type
8-
def compile_dir(dir: _Path, maxlevels: int = ..., ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern] = ..., quiet: int = ...) -> int: ...
9-
def compile_file(fullname: _Path, ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern] = ..., quiet: int = ...) -> int: ...
8+
def compile_dir(
9+
dir: _Path,
10+
maxlevels: int = ...,
11+
ddir: Optional[_Path] = ...,
12+
force: bool = ...,
13+
rx: Optional[Pattern[Any]] = ...,
14+
quiet: int = ...,
15+
) -> int: ...
16+
def compile_file(
17+
fullname: _Path, ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern[Any]] = ..., quiet: int = ...,
18+
) -> int: ...
1019
def compile_path(skip_curdir: bool = ..., maxlevels: int = ..., force: bool = ..., quiet: int = ...) -> int: ...

0 commit comments

Comments
 (0)