Skip to content

Commit 584a5d9

Browse files
koogorohauntsaninja
authored andcommitted
Sync typeshed
Source commit: python/typeshed@75cd302
1 parent bcf60ac commit 584a5d9

File tree

130 files changed

+1135
-1010
lines changed

Some content is hidden

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

130 files changed

+1135
-1010
lines changed

mypy/typeshed/stdlib/_codecs.pyi

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,35 +104,35 @@ if sys.version_info < (3, 8):
104104
def unicode_internal_decode(__obj: str | ReadableBuffer, __errors: str | None = None) -> tuple[str, int]: ...
105105
def unicode_internal_encode(__obj: str | ReadableBuffer, __errors: str | None = None) -> tuple[bytes, int]: ...
106106

107-
def utf_16_be_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
107+
def utf_16_be_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
108108
def utf_16_be_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ...
109-
def utf_16_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
109+
def utf_16_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
110110
def utf_16_encode(__str: str, __errors: str | None = None, __byteorder: int = 0) -> tuple[bytes, int]: ...
111111
def utf_16_ex_decode(
112-
__data: ReadableBuffer, __errors: str | None = None, __byteorder: int = 0, __final: int = False
112+
__data: ReadableBuffer, __errors: str | None = None, __byteorder: int = 0, __final: bool = False
113113
) -> tuple[str, int, int]: ...
114-
def utf_16_le_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
114+
def utf_16_le_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
115115
def utf_16_le_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ...
116-
def utf_32_be_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
116+
def utf_32_be_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
117117
def utf_32_be_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ...
118-
def utf_32_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
118+
def utf_32_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
119119
def utf_32_encode(__str: str, __errors: str | None = None, __byteorder: int = 0) -> tuple[bytes, int]: ...
120120
def utf_32_ex_decode(
121-
__data: ReadableBuffer, __errors: str | None = None, __byteorder: int = 0, __final: int = False
121+
__data: ReadableBuffer, __errors: str | None = None, __byteorder: int = 0, __final: bool = False
122122
) -> tuple[str, int, int]: ...
123-
def utf_32_le_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
123+
def utf_32_le_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
124124
def utf_32_le_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ...
125-
def utf_7_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
125+
def utf_7_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
126126
def utf_7_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ...
127-
def utf_8_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
127+
def utf_8_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
128128
def utf_8_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ...
129129

130130
if sys.platform == "win32":
131-
def mbcs_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
131+
def mbcs_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
132132
def mbcs_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ...
133133
def code_page_decode(
134-
__codepage: int, __data: ReadableBuffer, __errors: str | None = None, __final: int = False
134+
__codepage: int, __data: ReadableBuffer, __errors: str | None = None, __final: bool = False
135135
) -> tuple[str, int]: ...
136136
def code_page_encode(__code_page: int, __str: str, __errors: str | None = None) -> tuple[bytes, int]: ...
137-
def oem_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ...
137+
def oem_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ...
138138
def oem_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ...

mypy/typeshed/stdlib/_csv.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from _typeshed import SupportsWrite
22
from collections.abc import Iterable, Iterator
3-
from typing import Any, Union
4-
from typing_extensions import Literal, TypeAlias
3+
from typing import Any
4+
from typing_extensions import Final, Literal, TypeAlias
55

6-
__version__: str
6+
__version__: Final[str]
77

88
QUOTE_ALL: Literal[1]
99
QUOTE_MINIMAL: Literal[0]
@@ -27,7 +27,7 @@ class Dialect:
2727
strict: bool
2828
def __init__(self) -> None: ...
2929

30-
_DialectLike: TypeAlias = Union[str, Dialect, type[Dialect]]
30+
_DialectLike: TypeAlias = str | Dialect | type[Dialect]
3131

3232
class _reader(Iterator[list[str]]):
3333
@property

mypy/typeshed/stdlib/_decimal.pyi

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import numbers
22
import sys
3-
from _typeshed import Self
43
from collections.abc import Container, Sequence
54
from types import TracebackType
6-
from typing import Any, ClassVar, NamedTuple, Union, overload
7-
from typing_extensions import Literal, TypeAlias
5+
from typing import Any, ClassVar, NamedTuple, overload
6+
from typing_extensions import Final, Literal, Self, TypeAlias
87

98
_Decimal: TypeAlias = Decimal | int
10-
_DecimalNew: TypeAlias = Union[Decimal, float, str, tuple[int, Sequence[int], int]]
9+
_DecimalNew: TypeAlias = Decimal | float | str | tuple[int, Sequence[int], int]
1110
_ComparableNum: TypeAlias = Decimal | float | numbers.Rational
1211

13-
__version__: str
14-
__libmpdec_version__: str
12+
__version__: Final[str]
13+
__libmpdec_version__: Final[str]
1514

1615
class DecimalTuple(NamedTuple):
1716
sign: int
@@ -69,9 +68,9 @@ else:
6968
def localcontext(ctx: Context | None = None) -> _ContextManager: ...
7069

7170
class Decimal:
72-
def __new__(cls: type[Self], value: _DecimalNew = ..., context: Context | None = ...) -> Self: ...
71+
def __new__(cls, value: _DecimalNew = ..., context: Context | None = ...) -> Self: ...
7372
@classmethod
74-
def from_float(cls: type[Self], __f: float) -> Self: ...
73+
def from_float(cls, __f: float) -> Self: ...
7574
def __bool__(self) -> bool: ...
7675
def compare(self, other: _Decimal, context: Context | None = None) -> Decimal: ...
7776
def as_tuple(self) -> DecimalTuple: ...
@@ -163,9 +162,9 @@ class Decimal:
163162
def rotate(self, other: _Decimal, context: Context | None = None) -> Decimal: ...
164163
def scaleb(self, other: _Decimal, context: Context | None = None) -> Decimal: ...
165164
def shift(self, other: _Decimal, context: Context | None = None) -> Decimal: ...
166-
def __reduce__(self: Self) -> tuple[type[Self], tuple[str]]: ...
167-
def __copy__(self: Self) -> Self: ...
168-
def __deepcopy__(self: Self, __memo: Any) -> Self: ...
165+
def __reduce__(self) -> tuple[type[Self], tuple[str]]: ...
166+
def __copy__(self) -> Self: ...
167+
def __deepcopy__(self, __memo: Any) -> Self: ...
169168
def __format__(self, __specifier: str, __context: Context | None = ...) -> str: ...
170169

171170
class _ContextManager:
@@ -203,7 +202,7 @@ class Context:
203202
traps: None | dict[_TrapType, bool] | Container[_TrapType] = ...,
204203
_ignored_flags: list[_TrapType] | None = ...,
205204
) -> None: ...
206-
def __reduce__(self: Self) -> tuple[type[Self], tuple[Any, ...]]: ...
205+
def __reduce__(self) -> tuple[type[Self], tuple[Any, ...]]: ...
207206
def clear_flags(self) -> None: ...
208207
def clear_traps(self) -> None: ...
209208
def copy(self) -> Context: ...

mypy/typeshed/stdlib/_heapq.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from typing import Any, TypeVar
2+
from typing_extensions import Final
23

34
_T = TypeVar("_T")
45

5-
__about__: str
6+
__about__: Final[str]
67

78
def heapify(__heap: list[Any]) -> None: ...
89
def heappop(__heap: list[_T]) -> _T: ...

mypy/typeshed/stdlib/_py_abc.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from _typeshed import Self
1+
import _typeshed
22
from typing import Any, NewType, TypeVar
33

44
_T = TypeVar("_T")
@@ -8,5 +8,7 @@ _CacheToken = NewType("_CacheToken", int)
88
def get_cache_token() -> _CacheToken: ...
99

1010
class ABCMeta(type):
11-
def __new__(__mcls: type[Self], __name: str, __bases: tuple[type[Any], ...], __namespace: dict[str, Any]) -> Self: ...
11+
def __new__(
12+
__mcls: type[_typeshed.Self], __name: str, __bases: tuple[type[Any], ...], __namespace: dict[str, Any]
13+
) -> _typeshed.Self: ...
1214
def register(cls, subclass: type[_T]) -> type[_T]: ...

mypy/typeshed/stdlib/_typeshed/__init__.pyi

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import mmap
88
import pickle
99
import sys
1010
from collections.abc import Awaitable, Callable, Iterable, Set as AbstractSet
11+
from dataclasses import Field
1112
from os import PathLike
1213
from types import FrameType, TracebackType
13-
from typing import Any, AnyStr, Generic, Protocol, TypeVar, Union
14+
from typing import Any, AnyStr, ClassVar, Generic, Protocol, TypeVar
1415
from typing_extensions import Final, Literal, LiteralString, TypeAlias, final
1516

1617
_KT = TypeVar("_KT")
@@ -264,7 +265,7 @@ IndexableBuffer: TypeAlias = bytes | bytearray | memoryview | array.array[Any] |
264265
# def __buffer__(self, __flags: int) -> memoryview: ...
265266

266267
ExcInfo: TypeAlias = tuple[type[BaseException], BaseException, TracebackType]
267-
OptExcInfo: TypeAlias = Union[ExcInfo, tuple[None, None, None]]
268+
OptExcInfo: TypeAlias = ExcInfo | tuple[None, None, None]
268269

269270
# stable
270271
if sys.version_info >= (3, 10):
@@ -304,3 +305,10 @@ ProfileFunction: TypeAlias = Callable[[FrameType, str, Any], object]
304305

305306
# Objects suitable to be passed to sys.settrace, threading.settrace, and similar
306307
TraceFunction: TypeAlias = Callable[[FrameType, str, Any], TraceFunction | None]
308+
309+
# experimental
310+
# Might not work as expected for pyright, see
311+
# https://github.com/python/typeshed/pull/9362
312+
# https://github.com/microsoft/pyright/issues/4339
313+
class DataclassInstance(Protocol):
314+
__dataclass_fields__: ClassVar[dict[str, Field[Any]]]

mypy/typeshed/stdlib/_weakref.pyi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import sys
2-
from _typeshed import Self
32
from collections.abc import Callable
43
from typing import Any, Generic, TypeVar, overload
5-
from typing_extensions import final
4+
from typing_extensions import Self, final
65

76
if sys.version_info >= (3, 9):
87
from types import GenericAlias
@@ -21,7 +20,7 @@ class ProxyType(Generic[_T]): # "weakproxy"
2120

2221
class ReferenceType(Generic[_T]):
2322
__callback__: Callable[[ReferenceType[_T]], Any]
24-
def __new__(cls: type[Self], o: _T, callback: Callable[[ReferenceType[_T]], Any] | None = ...) -> Self: ...
23+
def __new__(cls, o: _T, callback: Callable[[ReferenceType[_T]], Any] | None = ...) -> Self: ...
2524
def __call__(self) -> _T | None: ...
2625
if sys.version_info >= (3, 9):
2726
def __class_getitem__(cls, item: Any) -> GenericAlias: ...

mypy/typeshed/stdlib/_weakrefset.pyi

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
2-
from _typeshed import Self
32
from collections.abc import Iterable, Iterator, MutableSet
43
from typing import Any, Generic, TypeVar, overload
4+
from typing_extensions import Self
55

66
if sys.version_info >= (3, 9):
77
from types import GenericAlias
@@ -18,21 +18,21 @@ class WeakSet(MutableSet[_T], Generic[_T]):
1818
def __init__(self, data: Iterable[_T]) -> None: ...
1919
def add(self, item: _T) -> None: ...
2020
def discard(self, item: _T) -> None: ...
21-
def copy(self: Self) -> Self: ...
21+
def copy(self) -> Self: ...
2222
def remove(self, item: _T) -> None: ...
2323
def update(self, other: Iterable[_T]) -> None: ...
2424
def __contains__(self, item: object) -> bool: ...
2525
def __len__(self) -> int: ...
2626
def __iter__(self) -> Iterator[_T]: ...
27-
def __ior__(self: Self, other: Iterable[_T]) -> Self: ... # type: ignore[override,misc]
28-
def difference(self: Self, other: Iterable[_T]) -> Self: ...
29-
def __sub__(self: Self, other: Iterable[Any]) -> Self: ...
27+
def __ior__(self, other: Iterable[_T]) -> Self: ... # type: ignore[override,misc]
28+
def difference(self, other: Iterable[_T]) -> Self: ...
29+
def __sub__(self, other: Iterable[Any]) -> Self: ...
3030
def difference_update(self, other: Iterable[Any]) -> None: ...
31-
def __isub__(self: Self, other: Iterable[Any]) -> Self: ...
32-
def intersection(self: Self, other: Iterable[_T]) -> Self: ...
33-
def __and__(self: Self, other: Iterable[Any]) -> Self: ...
31+
def __isub__(self, other: Iterable[Any]) -> Self: ...
32+
def intersection(self, other: Iterable[_T]) -> Self: ...
33+
def __and__(self, other: Iterable[Any]) -> Self: ...
3434
def intersection_update(self, other: Iterable[Any]) -> None: ...
35-
def __iand__(self: Self, other: Iterable[Any]) -> Self: ...
35+
def __iand__(self, other: Iterable[Any]) -> Self: ...
3636
def issubset(self, other: Iterable[_T]) -> bool: ...
3737
def __le__(self, other: Iterable[_T]) -> bool: ...
3838
def __lt__(self, other: Iterable[_T]) -> bool: ...
@@ -43,7 +43,7 @@ class WeakSet(MutableSet[_T], Generic[_T]):
4343
def symmetric_difference(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ...
4444
def __xor__(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ...
4545
def symmetric_difference_update(self, other: Iterable[_T]) -> None: ...
46-
def __ixor__(self: Self, other: Iterable[_T]) -> Self: ... # type: ignore[override,misc]
46+
def __ixor__(self, other: Iterable[_T]) -> Self: ... # type: ignore[override,misc]
4747
def union(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ...
4848
def __or__(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ...
4949
def isdisjoint(self, other: Iterable[_T]) -> bool: ...

0 commit comments

Comments
 (0)