Skip to content

Commit 8de8e87

Browse files
committed
Sync typeshed
Source commit: python/typeshed@45c0e52
1 parent bb63337 commit 8de8e87

File tree

149 files changed

+1558
-3263
lines changed

Some content is hidden

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

149 files changed

+1558
-3263
lines changed

mypy/typeshed/stdlib/VERSIONS

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ _curses: 3.0-
3636
_curses_panel: 3.0-
3737
_dbm: 3.0-
3838
_decimal: 3.3-
39-
_dummy_thread: 3.0-3.8
40-
_dummy_threading: 3.0-3.8
4139
_frozen_importlib: 3.0-
4240
_frozen_importlib_external: 3.5-
4341
_gdbm: 3.0-
@@ -140,15 +138,13 @@ distutils: 3.0-3.11
140138
distutils.command.bdist_msi: 3.0-3.10
141139
distutils.command.bdist_wininst: 3.0-3.9
142140
doctest: 3.0-
143-
dummy_threading: 3.0-3.8
144141
email: 3.0-
145142
encodings: 3.0-
146143
encodings.cp1125: 3.4-
147144
encodings.cp273: 3.4-
148145
encodings.cp858: 3.2-
149146
encodings.koi8_t: 3.5-
150147
encodings.kz1048: 3.5-
151-
encodings.mac_centeuro: 3.0-3.8
152148
ensurepip: 3.0-
153149
enum: 3.4-
154150
errno: 3.0-

mypy/typeshed/stdlib/_ast.pyi

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,6 @@ if sys.version_info >= (3, 10):
130130
pattern as pattern,
131131
)
132132

133-
if sys.version_info < (3, 9):
134-
from ast import (
135-
AugLoad as AugLoad,
136-
AugStore as AugStore,
137-
ExtSlice as ExtSlice,
138-
Index as Index,
139-
Param as Param,
140-
Suite as Suite,
141-
slice as slice,
142-
)
143-
144133
PyCF_ALLOW_TOP_LEVEL_AWAIT: Literal[8192]
145134
PyCF_ONLY_AST: Literal[1024]
146135
PyCF_TYPE_COMMENTS: Literal[4096]

mypy/typeshed/stdlib/_asyncio.pyi

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import sys
22
from asyncio.events import AbstractEventLoop
3-
from collections.abc import Awaitable, Callable, Coroutine, Generator, Iterable
3+
from collections.abc import Awaitable, Callable, Coroutine, Generator
44
from contextvars import Context
5-
from types import FrameType
5+
from types import FrameType, GenericAlias
66
from typing import Any, Literal, TextIO, TypeVar
77
from typing_extensions import Self, TypeAlias
88

9-
if sys.version_info >= (3, 9):
10-
from types import GenericAlias
11-
129
_T = TypeVar("_T")
1310
_T_co = TypeVar("_T_co", covariant=True)
1411
_TaskYieldType: TypeAlias = Future[object] | None
1512

16-
class Future(Awaitable[_T], Iterable[_T]):
13+
class Future(Awaitable[_T]):
1714
_state: str
1815
@property
1916
def _exception(self) -> BaseException | None: ...
@@ -29,11 +26,7 @@ class Future(Awaitable[_T], Iterable[_T]):
2926
@property
3027
def _callbacks(self) -> list[tuple[Callable[[Self], Any], Context]]: ...
3128
def add_done_callback(self, fn: Callable[[Self], object], /, *, context: Context | None = None) -> None: ...
32-
if sys.version_info >= (3, 9):
33-
def cancel(self, msg: Any | None = None) -> bool: ...
34-
else:
35-
def cancel(self) -> bool: ...
36-
29+
def cancel(self, msg: Any | None = None) -> bool: ...
3730
def cancelled(self) -> bool: ...
3831
def done(self) -> bool: ...
3932
def result(self) -> _T: ...
@@ -45,15 +38,12 @@ class Future(Awaitable[_T], Iterable[_T]):
4538
def __await__(self) -> Generator[Any, None, _T]: ...
4639
@property
4740
def _loop(self) -> AbstractEventLoop: ...
48-
if sys.version_info >= (3, 9):
49-
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
41+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
5042

5143
if sys.version_info >= (3, 12):
5244
_TaskCompatibleCoro: TypeAlias = Coroutine[Any, Any, _T_co]
53-
elif sys.version_info >= (3, 9):
54-
_TaskCompatibleCoro: TypeAlias = Generator[_TaskYieldType, None, _T_co] | Coroutine[Any, Any, _T_co]
5545
else:
56-
_TaskCompatibleCoro: TypeAlias = Generator[_TaskYieldType, None, _T_co] | Awaitable[_T_co]
46+
_TaskCompatibleCoro: TypeAlias = Generator[_TaskYieldType, None, _T_co] | Coroutine[Any, Any, _T_co]
5747

5848
# mypy and pyright complain that a subclass of an invariant class shouldn't be covariant.
5949
# While this is true in general, here it's sort-of okay to have a covariant subclass,
@@ -99,13 +89,8 @@ class Task(Future[_T_co]): # type: ignore[type-var] # pyright: ignore[reportIn
9989
if sys.version_info >= (3, 11):
10090
def cancelling(self) -> int: ...
10191
def uncancel(self) -> int: ...
102-
if sys.version_info < (3, 9):
103-
@classmethod
104-
def current_task(cls, loop: AbstractEventLoop | None = None) -> Task[Any] | None: ...
105-
@classmethod
106-
def all_tasks(cls, loop: AbstractEventLoop | None = None) -> set[Task[Any]]: ...
107-
if sys.version_info >= (3, 9):
108-
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
92+
93+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
10994

11095
def get_event_loop() -> AbstractEventLoop: ...
11196
def get_running_loop() -> AbstractEventLoop: ...

mypy/typeshed/stdlib/_blake2.pyi

Lines changed: 36 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
from _typeshed import ReadableBuffer
32
from typing import ClassVar, final
43
from typing_extensions import Self
@@ -21,44 +20,24 @@ class blake2b:
2120
block_size: int
2221
digest_size: int
2322
name: str
24-
if sys.version_info >= (3, 9):
25-
def __new__(
26-
cls,
27-
data: ReadableBuffer = b"",
28-
/,
29-
*,
30-
digest_size: int = 64,
31-
key: ReadableBuffer = b"",
32-
salt: ReadableBuffer = b"",
33-
person: ReadableBuffer = b"",
34-
fanout: int = 1,
35-
depth: int = 1,
36-
leaf_size: int = 0,
37-
node_offset: int = 0,
38-
node_depth: int = 0,
39-
inner_size: int = 0,
40-
last_node: bool = False,
41-
usedforsecurity: bool = True,
42-
) -> Self: ...
43-
else:
44-
def __new__(
45-
cls,
46-
data: ReadableBuffer = b"",
47-
/,
48-
*,
49-
digest_size: int = 64,
50-
key: ReadableBuffer = b"",
51-
salt: ReadableBuffer = b"",
52-
person: ReadableBuffer = b"",
53-
fanout: int = 1,
54-
depth: int = 1,
55-
leaf_size: int = 0,
56-
node_offset: int = 0,
57-
node_depth: int = 0,
58-
inner_size: int = 0,
59-
last_node: bool = False,
60-
) -> Self: ...
61-
23+
def __new__(
24+
cls,
25+
data: ReadableBuffer = b"",
26+
/,
27+
*,
28+
digest_size: int = 64,
29+
key: ReadableBuffer = b"",
30+
salt: ReadableBuffer = b"",
31+
person: ReadableBuffer = b"",
32+
fanout: int = 1,
33+
depth: int = 1,
34+
leaf_size: int = 0,
35+
node_offset: int = 0,
36+
node_depth: int = 0,
37+
inner_size: int = 0,
38+
last_node: bool = False,
39+
usedforsecurity: bool = True,
40+
) -> Self: ...
6241
def copy(self) -> Self: ...
6342
def digest(self) -> bytes: ...
6443
def hexdigest(self) -> str: ...
@@ -73,44 +52,24 @@ class blake2s:
7352
block_size: int
7453
digest_size: int
7554
name: str
76-
if sys.version_info >= (3, 9):
77-
def __new__(
78-
cls,
79-
data: ReadableBuffer = b"",
80-
/,
81-
*,
82-
digest_size: int = 32,
83-
key: ReadableBuffer = b"",
84-
salt: ReadableBuffer = b"",
85-
person: ReadableBuffer = b"",
86-
fanout: int = 1,
87-
depth: int = 1,
88-
leaf_size: int = 0,
89-
node_offset: int = 0,
90-
node_depth: int = 0,
91-
inner_size: int = 0,
92-
last_node: bool = False,
93-
usedforsecurity: bool = True,
94-
) -> Self: ...
95-
else:
96-
def __new__(
97-
cls,
98-
data: ReadableBuffer = b"",
99-
/,
100-
*,
101-
digest_size: int = 32,
102-
key: ReadableBuffer = b"",
103-
salt: ReadableBuffer = b"",
104-
person: ReadableBuffer = b"",
105-
fanout: int = 1,
106-
depth: int = 1,
107-
leaf_size: int = 0,
108-
node_offset: int = 0,
109-
node_depth: int = 0,
110-
inner_size: int = 0,
111-
last_node: bool = False,
112-
) -> Self: ...
113-
55+
def __new__(
56+
cls,
57+
data: ReadableBuffer = b"",
58+
/,
59+
*,
60+
digest_size: int = 32,
61+
key: ReadableBuffer = b"",
62+
salt: ReadableBuffer = b"",
63+
person: ReadableBuffer = b"",
64+
fanout: int = 1,
65+
depth: int = 1,
66+
leaf_size: int = 0,
67+
node_offset: int = 0,
68+
node_depth: int = 0,
69+
inner_size: int = 0,
70+
last_node: bool = False,
71+
usedforsecurity: bool = True,
72+
) -> Self: ...
11473
def copy(self) -> Self: ...
11574
def digest(self) -> bytes: ...
11675
def hexdigest(self) -> str: ...

mypy/typeshed/stdlib/_codecs.pyi

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,12 @@ def escape_decode(data: str | ReadableBuffer, errors: str | None = None, /) -> t
8181
def escape_encode(data: bytes, errors: str | None = None, /) -> tuple[bytes, int]: ...
8282
def latin_1_decode(data: ReadableBuffer, errors: str | None = None, /) -> tuple[str, int]: ...
8383
def latin_1_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
84-
85-
if sys.version_info >= (3, 9):
86-
def raw_unicode_escape_decode(
87-
data: str | ReadableBuffer, errors: str | None = None, final: bool = True, /
88-
) -> tuple[str, int]: ...
89-
90-
else:
91-
def raw_unicode_escape_decode(data: str | ReadableBuffer, errors: str | None = None, /) -> tuple[str, int]: ...
92-
84+
def raw_unicode_escape_decode(
85+
data: str | ReadableBuffer, errors: str | None = None, final: bool = True, /
86+
) -> tuple[str, int]: ...
9387
def raw_unicode_escape_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
9488
def readbuffer_encode(data: str | ReadableBuffer, errors: str | None = None, /) -> tuple[bytes, int]: ...
95-
96-
if sys.version_info >= (3, 9):
97-
def unicode_escape_decode(
98-
data: str | ReadableBuffer, errors: str | None = None, final: bool = True, /
99-
) -> tuple[str, int]: ...
100-
101-
else:
102-
def unicode_escape_decode(data: str | ReadableBuffer, errors: str | None = None, /) -> tuple[str, int]: ...
103-
89+
def unicode_escape_decode(data: str | ReadableBuffer, errors: str | None = None, final: bool = True, /) -> tuple[str, int]: ...
10490
def unicode_escape_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...
10591
def utf_16_be_decode(data: ReadableBuffer, errors: str | None = None, final: bool = False, /) -> tuple[str, int]: ...
10692
def utf_16_be_encode(str: str, errors: str | None = None, /) -> tuple[bytes, int]: ...

mypy/typeshed/stdlib/_collections_abc.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from abc import abstractmethod
33
from types import MappingProxyType
4-
from typing import ( # noqa: Y022,Y038
4+
from typing import ( # noqa: Y022,Y038,UP035
55
AbstractSet as Set,
66
AsyncGenerator as AsyncGenerator,
77
AsyncIterable as AsyncIterable,
@@ -61,7 +61,7 @@ __all__ = [
6161
"MutableSequence",
6262
]
6363
if sys.version_info < (3, 14):
64-
from typing import ByteString as ByteString # noqa: Y057
64+
from typing import ByteString as ByteString # noqa: Y057,UP035
6565

6666
__all__ += ["ByteString"]
6767

mypy/typeshed/stdlib/_contextvars.pyi

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import sys
21
from collections.abc import Callable, Iterator, Mapping
2+
from types import GenericAlias
33
from typing import Any, ClassVar, Generic, TypeVar, final, overload
44
from typing_extensions import ParamSpec, Self
55

6-
if sys.version_info >= (3, 9):
7-
from types import GenericAlias
8-
96
_T = TypeVar("_T")
107
_D = TypeVar("_D")
118
_P = ParamSpec("_P")
@@ -27,8 +24,7 @@ class ContextVar(Generic[_T]):
2724
def get(self, default: _D, /) -> _D | _T: ...
2825
def set(self, value: _T, /) -> Token[_T]: ...
2926
def reset(self, token: Token[_T], /) -> None: ...
30-
if sys.version_info >= (3, 9):
31-
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
27+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
3228

3329
@final
3430
class Token(Generic[_T]):
@@ -38,8 +34,7 @@ class Token(Generic[_T]):
3834
def old_value(self) -> Any: ... # returns either _T or MISSING, but that's hard to express
3935
MISSING: ClassVar[object]
4036
__hash__: ClassVar[None] # type: ignore[assignment]
41-
if sys.version_info >= (3, 9):
42-
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
37+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
4338

4439
def copy_context() -> Context: ...
4540

mypy/typeshed/stdlib/_ctypes.pyi

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ from _typeshed import ReadableBuffer, StrOrBytesPath, WriteableBuffer
44
from abc import abstractmethod
55
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
66
from ctypes import CDLL, ArgumentError as ArgumentError, c_void_p
7+
from types import GenericAlias
78
from typing import Any, ClassVar, Generic, TypeVar, final, overload, type_check_only
89
from typing_extensions import Self, TypeAlias
910

10-
if sys.version_info >= (3, 9):
11-
from types import GenericAlias
12-
1311
_T = TypeVar("_T")
1412
_CT = TypeVar("_CT", bound=_CData)
1513

@@ -286,9 +284,13 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType):
286284
def _type_(self) -> type[_CT]: ...
287285
@_type_.setter
288286
def _type_(self, value: type[_CT]) -> None: ...
289-
raw: bytes # Note: only available if _CT == c_char
287+
# Note: only available if _CT == c_char
288+
@property
289+
def raw(self) -> bytes: ...
290+
@raw.setter
291+
def raw(self, value: ReadableBuffer) -> None: ...
290292
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
291-
# TODO These methods cannot be annotated correctly at the moment.
293+
# TODO: These methods cannot be annotated correctly at the moment.
292294
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT
293295
# here, because of a special feature of ctypes.
294296
# By default, when accessing an element of an Array[_CT], the returned object has type _CT.
@@ -313,8 +315,7 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType):
313315
# Can't inherit from Sized because the metaclass conflict between
314316
# Sized and _CData prevents using _CDataMeta.
315317
def __len__(self) -> int: ...
316-
if sys.version_info >= (3, 9):
317-
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
318+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
318319

319320
def addressof(obj: _CData | _CDataType, /) -> int: ...
320321
def alignment(obj_or_type: _CData | _CDataType | type[_CData | _CDataType], /) -> int: ...

0 commit comments

Comments
 (0)