Skip to content

Commit 7a62481

Browse files
Sync typeshed (#16206)
Source commit: python/typeshed@559d31c
1 parent acccdd8 commit 7a62481

32 files changed

+404
-217
lines changed

mypy/typeshed/stdlib/_ctypes.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ class _CData(metaclass=_CDataMeta):
5656
_b_base_: int
5757
_b_needsfree_: bool
5858
_objects: Mapping[Any, int] | None
59+
# At runtime the following classmethods are available only on classes, not
60+
# on instances. This can't be reflected properly in the type system:
61+
#
62+
# Structure.from_buffer(...) # valid at runtime
63+
# Structure(...).from_buffer(...) # invalid at runtime
64+
#
5965
@classmethod
6066
def from_buffer(cls, source: WriteableBuffer, offset: int = ...) -> Self: ...
6167
@classmethod

mypy/typeshed/stdlib/_curses.pyi

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,7 @@ if sys.platform != "win32":
276276
def can_change_color() -> bool: ...
277277
def cbreak(__flag: bool = True) -> None: ...
278278
def color_content(__color_number: int) -> tuple[int, int, int]: ...
279-
# Changed in Python 3.8.8 and 3.9.2
280-
if sys.version_info >= (3, 8):
281-
def color_pair(pair_number: int) -> int: ...
282-
else:
283-
def color_pair(__color_number: int) -> int: ...
284-
279+
def color_pair(__pair_number: int) -> int: ...
285280
def curs_set(__visibility: int) -> int: ...
286281
def def_prog_mode() -> None: ...
287282
def def_shell_mode() -> None: ...
@@ -366,7 +361,10 @@ if sys.platform != "win32":
366361
) -> bytes: ...
367362
def typeahead(__fd: int) -> None: ...
368363
def unctrl(__ch: _ChType) -> bytes: ...
369-
def unget_wch(__ch: int | str) -> None: ...
364+
if sys.version_info < (3, 12) or sys.platform != "darwin":
365+
# The support for macos was dropped in 3.12
366+
def unget_wch(__ch: int | str) -> None: ...
367+
370368
def ungetch(__ch: _ChType) -> None: ...
371369
def ungetmouse(__id: int, __x: int, __y: int, __z: int, __bstate: int) -> None: ...
372370
def update_lines_cols() -> None: ...
@@ -441,10 +439,13 @@ if sys.platform != "win32":
441439
def getch(self) -> int: ...
442440
@overload
443441
def getch(self, y: int, x: int) -> int: ...
444-
@overload
445-
def get_wch(self) -> int | str: ...
446-
@overload
447-
def get_wch(self, y: int, x: int) -> int | str: ...
442+
if sys.version_info < (3, 12) or sys.platform != "darwin":
443+
# The support for macos was dropped in 3.12
444+
@overload
445+
def get_wch(self) -> int | str: ...
446+
@overload
447+
def get_wch(self, y: int, x: int) -> int | str: ...
448+
448449
@overload
449450
def getkey(self) -> str: ...
450451
@overload

mypy/typeshed/stdlib/_posixsubprocess.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ from typing_extensions import SupportsIndex
66
if sys.platform != "win32":
77
def cloexec_pipe() -> tuple[int, int]: ...
88
def fork_exec(
9-
__process_args: Sequence[StrOrBytesPath] | None,
9+
__args: Sequence[StrOrBytesPath] | None,
1010
__executable_list: Sequence[bytes],
1111
__close_fds: bool,
12-
__fds_to_keep: tuple[int, ...],
13-
__cwd_obj: str,
14-
__env_list: Sequence[bytes] | None,
12+
__pass_fds: tuple[int, ...],
13+
__cwd: str,
14+
__env: Sequence[bytes] | None,
1515
__p2cread: int,
1616
__p2cwrite: int,
17-
__c2pred: int,
17+
__c2pread: int,
1818
__c2pwrite: int,
1919
__errread: int,
2020
__errwrite: int,
@@ -23,9 +23,9 @@ if sys.platform != "win32":
2323
__restore_signals: int,
2424
__call_setsid: int,
2525
__pgid_to_set: int,
26-
__gid_object: SupportsIndex | None,
27-
__groups_list: list[int] | None,
28-
__uid_object: SupportsIndex | None,
26+
__gid: SupportsIndex | None,
27+
__extra_groups: list[int] | None,
28+
__uid: SupportsIndex | None,
2929
__child_umask: int,
3030
__preexec_fn: Callable[[], None],
3131
__allow_vfork: bool,

mypy/typeshed/stdlib/_typeshed/__init__.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ from collections.abc import Awaitable, Callable, Iterable, Sequence, Set as Abst
77
from dataclasses import Field
88
from os import PathLike
99
from types import FrameType, TracebackType
10-
from typing import Any, AnyStr, ClassVar, Generic, Protocol, TypeVar, overload
11-
from typing_extensions import Buffer, Final, Literal, LiteralString, TypeAlias, final
10+
from typing import Any, AnyStr, ClassVar, Generic, Protocol, SupportsFloat, SupportsInt, TypeVar, overload
11+
from typing_extensions import Buffer, Final, Literal, LiteralString, SupportsIndex, TypeAlias, final
1212

1313
_KT = TypeVar("_KT")
1414
_KT_co = TypeVar("_KT_co", covariant=True)
@@ -312,3 +312,7 @@ TraceFunction: TypeAlias = Callable[[FrameType, str, Any], TraceFunction | None]
312312
# https://github.com/microsoft/pyright/issues/4339
313313
class DataclassInstance(Protocol):
314314
__dataclass_fields__: ClassVar[dict[str, Field[Any]]]
315+
316+
# Anything that can be passed to the int/float constructors
317+
ConvertibleToInt: TypeAlias = str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc
318+
ConvertibleToFloat: TypeAlias = str | ReadableBuffer | SupportsFloat | SupportsIndex

mypy/typeshed/stdlib/abc.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class abstractstaticmethod(staticmethod[_P, _R_co]):
4040
class abstractproperty(property):
4141
__isabstractmethod__: Literal[True]
4242

43-
class ABC(metaclass=ABCMeta): ...
43+
class ABC(metaclass=ABCMeta):
44+
__slots__ = ()
4445

4546
def get_cache_token() -> object: ...
4647

mypy/typeshed/stdlib/ast.pyi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@ class NodeVisitor:
138138
def visit_withitem(self, node: withitem) -> Any: ...
139139
if sys.version_info >= (3, 10):
140140
def visit_Match(self, node: Match) -> Any: ...
141+
def visit_match_case(self, node: match_case) -> Any: ...
141142
def visit_MatchValue(self, node: MatchValue) -> Any: ...
142143
def visit_MatchSequence(self, node: MatchSequence) -> Any: ...
144+
def visit_MatchSingleton(self, node: MatchSingleton) -> Any: ...
143145
def visit_MatchStar(self, node: MatchStar) -> Any: ...
144146
def visit_MatchMapping(self, node: MatchMapping) -> Any: ...
145147
def visit_MatchClass(self, node: MatchClass) -> Any: ...
@@ -149,6 +151,12 @@ class NodeVisitor:
149151
if sys.version_info >= (3, 11):
150152
def visit_TryStar(self, node: TryStar) -> Any: ...
151153

154+
if sys.version_info >= (3, 12):
155+
def visit_TypeVar(self, node: TypeVar) -> Any: ...
156+
def visit_ParamSpec(self, node: ParamSpec) -> Any: ...
157+
def visit_TypeVarTuple(self, node: TypeVarTuple) -> Any: ...
158+
def visit_TypeAlias(self, node: TypeAlias) -> Any: ...
159+
152160
# visit methods for deprecated nodes
153161
def visit_ExtSlice(self, node: ExtSlice) -> Any: ...
154162
def visit_Index(self, node: Index) -> Any: ...

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import types
55
from _collections_abc import dict_items, dict_keys, dict_values
66
from _typeshed import (
77
AnyStr_co,
8+
ConvertibleToFloat,
9+
ConvertibleToInt,
810
FileDescriptorOrPath,
911
OpenBinaryMode,
1012
OpenBinaryModeReading,
@@ -24,7 +26,6 @@ from _typeshed import (
2426
SupportsRDivMod,
2527
SupportsRichComparison,
2628
SupportsRichComparisonT,
27-
SupportsTrunc,
2829
SupportsWrite,
2930
)
3031
from collections.abc import Awaitable, Callable, Iterable, Iterator, MutableSet, Reversible, Set as AbstractSet, Sized
@@ -48,7 +49,6 @@ from typing import ( # noqa: Y022
4849
SupportsBytes,
4950
SupportsComplex,
5051
SupportsFloat,
51-
SupportsInt,
5252
TypeVar,
5353
overload,
5454
type_check_only,
@@ -220,7 +220,7 @@ _LiteralInteger = _PositiveInteger | _NegativeInteger | Literal[0] # noqa: Y026
220220

221221
class int:
222222
@overload
223-
def __new__(cls, __x: str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc = ...) -> Self: ...
223+
def __new__(cls, __x: ConvertibleToInt = ...) -> Self: ...
224224
@overload
225225
def __new__(cls, __x: str | bytes | bytearray, base: SupportsIndex) -> Self: ...
226226
if sys.version_info >= (3, 8):
@@ -326,7 +326,7 @@ class int:
326326
def __index__(self) -> int: ...
327327

328328
class float:
329-
def __new__(cls, __x: SupportsFloat | SupportsIndex | str | ReadableBuffer = ...) -> Self: ...
329+
def __new__(cls, __x: ConvertibleToFloat = ...) -> Self: ...
330330
def as_integer_ratio(self) -> tuple[int, int]: ...
331331
def hex(self) -> str: ...
332332
def is_integer(self) -> bool: ...
@@ -774,7 +774,7 @@ class memoryview(Sequence[int]):
774774
def contiguous(self) -> bool: ...
775775
@property
776776
def nbytes(self) -> int: ...
777-
def __init__(self, obj: ReadableBuffer) -> None: ...
777+
def __new__(cls, obj: ReadableBuffer) -> Self: ...
778778
def __enter__(self) -> Self: ...
779779
def __exit__(
780780
self, __exc_type: type[BaseException] | None, __exc_val: BaseException | None, __exc_tb: TracebackType | None
@@ -853,9 +853,9 @@ class slice:
853853
@property
854854
def stop(self) -> Any: ...
855855
@overload
856-
def __init__(self, __stop: Any) -> None: ...
856+
def __new__(cls, __stop: Any) -> Self: ...
857857
@overload
858-
def __init__(self, __start: Any, __stop: Any, __step: Any = ...) -> None: ...
858+
def __new__(cls, __start: Any, __stop: Any, __step: Any = ...) -> Self: ...
859859
def __eq__(self, __value: object) -> bool: ...
860860
__hash__: ClassVar[None] # type: ignore[assignment]
861861
def indices(self, __len: SupportsIndex) -> tuple[int, int, int]: ...
@@ -1110,7 +1110,7 @@ class frozenset(AbstractSet[_T_co], Generic[_T_co]):
11101110
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
11111111

11121112
class enumerate(Iterator[tuple[int, _T]], Generic[_T]):
1113-
def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ...
1113+
def __new__(cls, iterable: Iterable[_T], start: int = ...) -> Self: ...
11141114
def __iter__(self) -> Self: ...
11151115
def __next__(self) -> tuple[int, _T]: ...
11161116
if sys.version_info >= (3, 9):
@@ -1125,9 +1125,9 @@ class range(Sequence[int]):
11251125
@property
11261126
def step(self) -> int: ...
11271127
@overload
1128-
def __init__(self, __stop: SupportsIndex) -> None: ...
1128+
def __new__(cls, __stop: SupportsIndex) -> Self: ...
11291129
@overload
1130-
def __init__(self, __start: SupportsIndex, __stop: SupportsIndex, __step: SupportsIndex = ...) -> None: ...
1130+
def __new__(cls, __start: SupportsIndex, __stop: SupportsIndex, __step: SupportsIndex = ...) -> Self: ...
11311131
def count(self, __value: int) -> int: ...
11321132
def index(self, __value: int) -> int: ... # type: ignore[override]
11331133
def __len__(self) -> int: ...
@@ -1320,11 +1320,11 @@ def exit(code: sys._ExitCode = None) -> NoReturn: ...
13201320

13211321
class filter(Iterator[_T], Generic[_T]):
13221322
@overload
1323-
def __init__(self, __function: None, __iterable: Iterable[_T | None]) -> None: ...
1323+
def __new__(cls, __function: None, __iterable: Iterable[_T | None]) -> Self: ...
13241324
@overload
1325-
def __init__(self, __function: Callable[[_S], TypeGuard[_T]], __iterable: Iterable[_S]) -> None: ...
1325+
def __new__(cls, __function: Callable[[_S], TypeGuard[_T]], __iterable: Iterable[_S]) -> Self: ...
13261326
@overload
1327-
def __init__(self, __function: Callable[[_T], Any], __iterable: Iterable[_T]) -> None: ...
1327+
def __new__(cls, __function: Callable[[_T], Any], __iterable: Iterable[_T]) -> Self: ...
13281328
def __iter__(self) -> Self: ...
13291329
def __next__(self) -> _T: ...
13301330

@@ -1379,35 +1379,35 @@ def locals() -> dict[str, Any]: ...
13791379

13801380
class map(Iterator[_S], Generic[_S]):
13811381
@overload
1382-
def __init__(self, __func: Callable[[_T1], _S], __iter1: Iterable[_T1]) -> None: ...
1382+
def __new__(cls, __func: Callable[[_T1], _S], __iter1: Iterable[_T1]) -> Self: ...
13831383
@overload
1384-
def __init__(self, __func: Callable[[_T1, _T2], _S], __iter1: Iterable[_T1], __iter2: Iterable[_T2]) -> None: ...
1384+
def __new__(cls, __func: Callable[[_T1, _T2], _S], __iter1: Iterable[_T1], __iter2: Iterable[_T2]) -> Self: ...
13851385
@overload
1386-
def __init__(
1387-
self, __func: Callable[[_T1, _T2, _T3], _S], __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3]
1388-
) -> None: ...
1386+
def __new__(
1387+
cls, __func: Callable[[_T1, _T2, _T3], _S], __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3]
1388+
) -> Self: ...
13891389
@overload
1390-
def __init__(
1391-
self,
1390+
def __new__(
1391+
cls,
13921392
__func: Callable[[_T1, _T2, _T3, _T4], _S],
13931393
__iter1: Iterable[_T1],
13941394
__iter2: Iterable[_T2],
13951395
__iter3: Iterable[_T3],
13961396
__iter4: Iterable[_T4],
1397-
) -> None: ...
1397+
) -> Self: ...
13981398
@overload
1399-
def __init__(
1400-
self,
1399+
def __new__(
1400+
cls,
14011401
__func: Callable[[_T1, _T2, _T3, _T4, _T5], _S],
14021402
__iter1: Iterable[_T1],
14031403
__iter2: Iterable[_T2],
14041404
__iter3: Iterable[_T3],
14051405
__iter4: Iterable[_T4],
14061406
__iter5: Iterable[_T5],
1407-
) -> None: ...
1407+
) -> Self: ...
14081408
@overload
1409-
def __init__(
1410-
self,
1409+
def __new__(
1410+
cls,
14111411
__func: Callable[..., _S],
14121412
__iter1: Iterable[Any],
14131413
__iter2: Iterable[Any],
@@ -1416,7 +1416,7 @@ class map(Iterator[_S], Generic[_S]):
14161416
__iter5: Iterable[Any],
14171417
__iter6: Iterable[Any],
14181418
*iterables: Iterable[Any],
1419-
) -> None: ...
1419+
) -> Self: ...
14201420
def __iter__(self) -> Self: ...
14211421
def __next__(self) -> _S: ...
14221422

@@ -1725,6 +1725,8 @@ def vars(__object: Any = ...) -> dict[str, Any]: ...
17251725

17261726
class zip(Iterator[_T_co], Generic[_T_co]):
17271727
if sys.version_info >= (3, 10):
1728+
@overload
1729+
def __new__(cls, *, strict: bool = ...) -> zip[Any]: ...
17281730
@overload
17291731
def __new__(cls, __iter1: Iterable[_T1], *, strict: bool = ...) -> zip[tuple[_T1]]: ...
17301732
@overload
@@ -1767,6 +1769,8 @@ class zip(Iterator[_T_co], Generic[_T_co]):
17671769
strict: bool = ...,
17681770
) -> zip[tuple[Any, ...]]: ...
17691771
else:
1772+
@overload
1773+
def __new__(cls) -> zip[Any]: ...
17701774
@overload
17711775
def __new__(cls, __iter1: Iterable[_T1]) -> zip[tuple[_T1]]: ...
17721776
@overload
@@ -1812,11 +1816,17 @@ def __import__(
18121816
) -> types.ModuleType: ...
18131817
def __build_class__(__func: Callable[[], _Cell | Any], __name: str, *bases: Any, metaclass: Any = ..., **kwds: Any) -> Any: ...
18141818

1815-
# Actually the type of Ellipsis is <type 'ellipsis'>, but since it's
1816-
# not exposed anywhere under that name, we make it private here.
1817-
@final
1818-
@type_check_only
1819-
class ellipsis: ...
1819+
if sys.version_info >= (3, 10):
1820+
# In Python 3.10, EllipsisType is exposed publicly in the types module.
1821+
@final
1822+
class ellipsis: ...
1823+
1824+
else:
1825+
# Actually the type of Ellipsis is <type 'ellipsis'>, but since it's
1826+
# not exposed anywhere under that name, we make it private here.
1827+
@final
1828+
@type_check_only
1829+
class ellipsis: ...
18201830

18211831
Ellipsis: ellipsis
18221832

mypy/typeshed/stdlib/codecs.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,16 @@ class _Stream(_WritableStream, _ReadableStream, Protocol): ...
7878
# They were much more common in Python 2 than in Python 3.
7979

8080
class _Encoder(Protocol):
81-
def __call__(self, input: str, errors: str = ...) -> tuple[bytes, int]: ... # signature of Codec().encode
81+
def __call__(self, __input: str, __errors: str = ...) -> tuple[bytes, int]: ... # signature of Codec().encode
8282

8383
class _Decoder(Protocol):
84-
def __call__(self, input: bytes, errors: str = ...) -> tuple[str, int]: ... # signature of Codec().decode
84+
def __call__(self, __input: bytes, __errors: str = ...) -> tuple[str, int]: ... # signature of Codec().decode
8585

8686
class _StreamReader(Protocol):
87-
def __call__(self, stream: _ReadableStream, errors: str = ...) -> StreamReader: ...
87+
def __call__(self, __stream: _ReadableStream, __errors: str = ...) -> StreamReader: ...
8888

8989
class _StreamWriter(Protocol):
90-
def __call__(self, stream: _WritableStream, errors: str = ...) -> StreamWriter: ...
90+
def __call__(self, __stream: _WritableStream, __errors: str = ...) -> StreamWriter: ...
9191

9292
class _IncrementalEncoder(Protocol):
9393
def __call__(self, errors: str = ...) -> IncrementalEncoder: ...

mypy/typeshed/stdlib/collections/__init__.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,15 @@ class OrderedDict(dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):
373373
@overload
374374
def setdefault(self, key: _KT, default: _VT) -> _VT: ...
375375
def __eq__(self, __value: object) -> bool: ...
376+
if sys.version_info >= (3, 9):
377+
@overload
378+
def __or__(self, __value: dict[_KT, _VT]) -> Self: ...
379+
@overload
380+
def __or__(self, __value: dict[_T1, _T2]) -> OrderedDict[_KT | _T1, _VT | _T2]: ...
381+
@overload
382+
def __ror__(self, __value: dict[_KT, _VT]) -> Self: ...
383+
@overload
384+
def __ror__(self, __value: dict[_T1, _T2]) -> OrderedDict[_KT | _T1, _VT | _T2]: ... # type: ignore[misc]
376385

377386
class defaultdict(dict[_KT, _VT], Generic[_KT, _VT]):
378387
default_factory: Callable[[], _VT] | None

mypy/typeshed/stdlib/fcntl.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ if sys.platform != "win32":
101101
I_STR: int
102102
I_SWROPT: int
103103
I_UNLINK: int
104+
105+
if sys.version_info >= (3, 12) and sys.platform == "linux":
106+
FICLONE: int
107+
FICLONERANGE: int
108+
104109
@overload
105110
def fcntl(__fd: FileDescriptorLike, __cmd: int, __arg: int = 0) -> int: ...
106111
@overload

mypy/typeshed/stdlib/http/server.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
5454
extensions_map: dict[str, str]
5555
if sys.version_info >= (3, 12):
5656
index_pages: ClassVar[tuple[str, ...]]
57+
directory: str
5758
def __init__(
5859
self,
5960
request: socketserver._RequestType,

0 commit comments

Comments
 (0)