Skip to content

Commit d131e91

Browse files
authored
Sync typeshed (#10862)
Source commit: python/typeshed@581b2d5 * add some fixtures Co-authored-by: hauntsaninja <>
1 parent 18ff207 commit d131e91

Some content is hidden

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

101 files changed

+2416
-1246
lines changed

mypy/typeshed/stdlib/@python2/__builtin__.pyi

+5
Original file line numberDiff line numberDiff line change
@@ -863,9 +863,14 @@ def filter(__function: Callable[[_T], Any], __iterable: Iterable[_T]) -> List[_T
863863
def format(__value: object, __format_spec: str = ...) -> str: ... # TODO unicode
864864
@overload
865865
def getattr(__o: Any, name: Text) -> Any: ...
866+
867+
# While technically covered by the last overload, spelling out the types for None and bool
868+
# help mypy out in some tricky situations involving type context (aka bidirectional inference)
866869
@overload
867870
def getattr(__o: Any, name: Text, __default: None) -> Optional[Any]: ...
868871
@overload
872+
def getattr(__o: Any, name: Text, __default: bool) -> Union[Any, bool]: ...
873+
@overload
869874
def getattr(__o: Any, name: Text, __default: _T) -> Union[Any, _T]: ...
870875
def globals() -> Dict[str, Any]: ...
871876
def hasattr(__obj: Any, __name: Text) -> bool: ...

mypy/typeshed/stdlib/@python2/_io.pyi

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from _typeshed import Self
12
from mmap import mmap
23
from typing import IO, Any, BinaryIO, Iterable, List, Optional, Text, TextIO, Tuple, Type, TypeVar, Union
34

@@ -30,7 +31,7 @@ class _IOBase(BinaryIO):
3031
def tell(self) -> int: ...
3132
def truncate(self, size: Optional[int] = ...) -> int: ...
3233
def writable(self) -> bool: ...
33-
def __enter__(self: _T) -> _T: ...
34+
def __enter__(self: Self) -> Self: ...
3435
def __exit__(
3536
self, t: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[Any]
3637
) -> Optional[bool]: ...
@@ -56,7 +57,7 @@ class _BufferedIOBase(_IOBase):
5657
class BufferedRWPair(_BufferedIOBase):
5758
def __init__(self, reader: _RawIOBase, writer: _RawIOBase, buffer_size: int = ..., max_buffer_size: int = ...) -> None: ...
5859
def peek(self, n: int = ...) -> bytes: ...
59-
def __enter__(self) -> BufferedRWPair: ...
60+
def __enter__(self: Self) -> Self: ...
6061

6162
class BufferedRandom(_BufferedIOBase):
6263
mode: str
@@ -140,7 +141,7 @@ class _TextIOBase(TextIO):
140141
def writable(self) -> bool: ...
141142
def write(self, pbuf: unicode) -> int: ...
142143
def writelines(self, lines: Iterable[unicode]) -> None: ...
143-
def __enter__(self: _T) -> _T: ...
144+
def __enter__(self: Self) -> Self: ...
144145
def __exit__(
145146
self, t: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[Any]
146147
) -> Optional[bool]: ...

mypy/typeshed/stdlib/@python2/_typeshed/__init__.pyi

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ _T = TypeVar("_T")
2626
_T_co = TypeVar("_T_co", covariant=True)
2727
_T_contra = TypeVar("_T_contra", contravariant=True)
2828

29+
# Use for "self" annotations:
30+
# def __enter__(self: Self) -> Self: ...
31+
Self = TypeVar("Self") # noqa Y001
32+
2933
class IdentityFunction(Protocol):
3034
def __call__(self, __x: _T) -> _T: ...
3135

mypy/typeshed/stdlib/@python2/abc.pyi

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import _weakrefset
2+
from _typeshed import SupportsWrite
23
from typing import Any, Callable, Dict, Set, Tuple, Type, TypeVar
34

45
_FuncT = TypeVar("_FuncT", bound=Callable[..., Any])
@@ -8,17 +9,16 @@ _FuncT = TypeVar("_FuncT", bound=Callable[..., Any])
89
def abstractmethod(funcobj: _FuncT) -> _FuncT: ...
910

1011
class ABCMeta(type):
11-
# TODO: FrozenSet
12-
__abstractmethods__: Set[Any]
12+
__abstractmethods__: frozenset[str]
1313
_abc_cache: _weakrefset.WeakSet[Any]
1414
_abc_invalidation_counter: int
1515
_abc_negative_cache: _weakrefset.WeakSet[Any]
1616
_abc_negative_cache_version: int
1717
_abc_registry: _weakrefset.WeakSet[Any]
18-
def __init__(self, name: str, bases: Tuple[type, ...], namespace: Dict[Any, Any]) -> None: ...
18+
def __init__(self, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> None: ...
1919
def __instancecheck__(cls: ABCMeta, instance: Any) -> Any: ...
2020
def __subclasscheck__(cls: ABCMeta, subclass: Any) -> Any: ...
21-
def _dump_registry(cls: ABCMeta, *args: Any, **kwargs: Any) -> None: ...
21+
def _dump_registry(cls: ABCMeta, file: SupportsWrite[Any] | None = ...) -> None: ...
2222
def register(cls: ABCMeta, subclass: Type[Any]) -> None: ...
2323

2424
# TODO: The real abc.abstractproperty inherits from "property".

mypy/typeshed/stdlib/@python2/builtins.pyi

+5
Original file line numberDiff line numberDiff line change
@@ -863,9 +863,14 @@ def filter(__function: Callable[[_T], Any], __iterable: Iterable[_T]) -> List[_T
863863
def format(__value: object, __format_spec: str = ...) -> str: ... # TODO unicode
864864
@overload
865865
def getattr(__o: Any, name: Text) -> Any: ...
866+
867+
# While technically covered by the last overload, spelling out the types for None and bool
868+
# help mypy out in some tricky situations involving type context (aka bidirectional inference)
866869
@overload
867870
def getattr(__o: Any, name: Text, __default: None) -> Optional[Any]: ...
868871
@overload
872+
def getattr(__o: Any, name: Text, __default: bool) -> Union[Any, bool]: ...
873+
@overload
869874
def getattr(__o: Any, name: Text, __default: _T) -> Union[Any, _T]: ...
870875
def globals() -> Dict[str, Any]: ...
871876
def hasattr(__obj: Any, __name: Text) -> bool: ...

mypy/typeshed/stdlib/@python2/mmap.pyi

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
from typing import AnyStr, Generic, Optional, Sequence, Union
2+
from typing import NoReturn, Optional, Sequence, Union
33

44
ACCESS_DEFAULT: int
55
ACCESS_READ: int
@@ -23,7 +23,7 @@ if sys.platform != "win32":
2323

2424
PAGESIZE: int
2525

26-
class _mmap(Generic[AnyStr]):
26+
class mmap(Sequence[bytes]):
2727
if sys.platform == "win32":
2828
def __init__(
2929
self, fileno: int, length: int, tagname: Optional[str] = ..., access: int = ..., offset: int = ...
@@ -35,21 +35,19 @@ class _mmap(Generic[AnyStr]):
3535
def close(self) -> None: ...
3636
def flush(self, offset: int = ..., size: int = ...) -> int: ...
3737
def move(self, dest: int, src: int, count: int) -> None: ...
38-
def read_byte(self) -> AnyStr: ...
39-
def readline(self) -> AnyStr: ...
38+
def read_byte(self) -> bytes: ...
39+
def readline(self) -> bytes: ...
4040
def resize(self, newsize: int) -> None: ...
4141
def seek(self, pos: int, whence: int = ...) -> None: ...
4242
def size(self) -> int: ...
4343
def tell(self) -> int: ...
44-
def write_byte(self, byte: AnyStr) -> None: ...
44+
def write_byte(self, byte: bytes) -> None: ...
4545
def __len__(self) -> int: ...
46-
47-
class mmap(_mmap[bytes], Sequence[bytes]):
4846
def find(self, string: bytes, start: int = ..., end: int = ...) -> int: ...
4947
def rfind(self, string: bytes, start: int = ..., stop: int = ...) -> int: ...
5048
def read(self, num: int) -> bytes: ...
5149
def write(self, string: bytes) -> None: ...
5250
def __getitem__(self, index: Union[int, slice]) -> bytes: ...
5351
def __getslice__(self, i: Optional[int], j: Optional[int]) -> bytes: ...
54-
def __delitem__(self, index: Union[int, slice]) -> None: ...
52+
def __delitem__(self, index: Union[int, slice]) -> NoReturn: ...
5553
def __setitem__(self, index: Union[int, slice], object: bytes) -> None: ...

mypy/typeshed/stdlib/@python2/sysconfig.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def get_config_vars() -> Dict[str, Any]: ...
77
def get_config_vars(arg: str, *args: str) -> List[Any]: ...
88
def get_scheme_names() -> Tuple[str, ...]: ...
99
def get_path_names() -> Tuple[str, ...]: ...
10-
def get_path(name: str, scheme: str = ..., vars: Optional[Dict[str, Any]] = ..., expand: bool = ...) -> Optional[str]: ...
10+
def get_path(name: str, scheme: str = ..., vars: Optional[Dict[str, Any]] = ..., expand: bool = ...) -> str: ...
1111
def get_paths(scheme: str = ..., vars: Optional[Dict[str, Any]] = ..., expand: bool = ...) -> Dict[str, str]: ...
1212
def get_python_version() -> str: ...
1313
def get_platform() -> str: ...

mypy/typeshed/stdlib/VERSIONS

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _ast: 2.7-
2323
_bisect: 2.7-
2424
_bootlocale: 3.6-3.9
2525
_codecs: 2.7-
26-
_collections_abc: 3.6-
26+
_collections_abc: 3.3-
2727
_compat_pickle: 3.6-
2828
_compression: 3.6-
2929
_csv: 2.7-
@@ -43,6 +43,7 @@ _py_abc: 3.7-
4343
_pydecimal: 3.6-
4444
_random: 2.7-
4545
_sitebuiltins: 3.6-
46+
_socket: 3.0- # present in 2.7 at runtime, but not in typeshed
4647
_stat: 3.6-
4748
_thread: 2.7-
4849
_threading_local: 3.6-
@@ -82,6 +83,7 @@ code: 2.7-
8283
codecs: 2.7-
8384
codeop: 2.7-
8485
collections: 2.7-
86+
collections.abc: 3.3-
8587
colorsys: 2.7-
8688
compileall: 2.7-
8789
concurrent: 3.2-
@@ -135,6 +137,7 @@ imaplib: 2.7-
135137
imghdr: 2.7-
136138
imp: 2.7-
137139
importlib: 2.7-
140+
importlib.metadata: 3.8-
138141
importlib.resources: 3.7-
139142
inspect: 2.7-
140143
io: 2.7-

mypy/typeshed/stdlib/__future__.pyi

+28
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,31 @@ if sys.version_info >= (3, 7):
2121
annotations: _Feature
2222

2323
all_feature_names: List[str] # undocumented
24+
25+
if sys.version_info >= (3, 7):
26+
__all__ = [
27+
"all_feature_names",
28+
"absolute_import",
29+
"division",
30+
"generators",
31+
"nested_scopes",
32+
"print_function",
33+
"unicode_literals",
34+
"with_statement",
35+
"barry_as_FLUFL",
36+
"generator_stop",
37+
"annotations",
38+
]
39+
else:
40+
__all__ = [
41+
"all_feature_names",
42+
"absolute_import",
43+
"division",
44+
"generators",
45+
"nested_scopes",
46+
"print_function",
47+
"unicode_literals",
48+
"with_statement",
49+
"barry_as_FLUFL",
50+
"generator_stop",
51+
]

mypy/typeshed/stdlib/_ast.pyi

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
import typing
33
from typing import Any, ClassVar, Optional
4+
from typing_extensions import Literal
45

56
PyCF_ONLY_AST: int
67
if sys.version_info >= (3, 8):
@@ -390,7 +391,7 @@ if sys.version_info >= (3, 10):
390391
class MatchValue(pattern):
391392
value: expr
392393
class MatchSingleton(pattern):
393-
value: Optional[bool]
394+
value: Literal[True, False, None]
394395
class MatchSequence(pattern):
395396
patterns: typing.List[pattern]
396397
class MatchStar(pattern):

mypy/typeshed/stdlib/_curses.pyi

+11
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ BUTTON4_DOUBLE_CLICKED: int
8989
BUTTON4_PRESSED: int
9090
BUTTON4_RELEASED: int
9191
BUTTON4_TRIPLE_CLICKED: int
92+
# Darwin ncurses doesn't provide BUTTON5_* constants
93+
if sys.version_info >= (3, 10) and sys.platform != "darwin":
94+
BUTTON5_PRESSED: int
95+
BUTTON5_RELEASED: int
96+
BUTTON5_CLICKED: int
97+
BUTTON5_DOUBLE_CLICKED: int
98+
BUTTON5_TRIPLE_CLICKED: int
9299
BUTTON_ALT: int
93100
BUTTON_CTRL: int
94101
BUTTON_SHIFT: int
@@ -291,6 +298,10 @@ def getsyx() -> Tuple[int, int]: ...
291298
def getwin(__file: BinaryIO) -> _CursesWindow: ...
292299
def halfdelay(__tenths: int) -> None: ...
293300
def has_colors() -> bool: ...
301+
302+
if sys.version_info >= (3, 10):
303+
def has_extended_color_support() -> bool: ...
304+
294305
def has_ic() -> bool: ...
295306
def has_il() -> bool: ...
296307
def has_key(__key: int) -> bool: ...

0 commit comments

Comments
 (0)