Skip to content

Commit 7a6ecd3

Browse files
authored
Sync typeshed (#12982)
* Sync typeshed Source commit: python/typeshed@91d6383 * fix tests Co-authored-by: hauntsaninja <>
1 parent eaf6091 commit 7a6ecd3

File tree

129 files changed

+3480
-3705
lines changed

Some content is hidden

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

129 files changed

+3480
-3705
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,12 @@ class SSLContext:
225225
def load_verify_locations(
226226
self, cafile: StrPath | None = ..., capath: StrPath | None = ..., cadata: Text | bytes | None = ...
227227
) -> None: ...
228-
def get_ca_certs(self, binary_form: bool = ...) -> list[_PeerCertRetDictType] | list[bytes]: ...
228+
@overload
229+
def get_ca_certs(self, binary_form: Literal[False] = ...) -> list[_PeerCertRetDictType]: ...
230+
@overload
231+
def get_ca_certs(self, binary_form: Literal[True]) -> list[bytes]: ...
232+
@overload
233+
def get_ca_certs(self, binary_form: bool = ...) -> Any: ...
229234
def set_default_verify_paths(self) -> None: ...
230235
def set_ciphers(self, __cipherlist: str) -> None: ...
231236
def set_alpn_protocols(self, alpn_protocols: Iterable[str]) -> None: ...

mypy/typeshed/stdlib/VERSIONS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ asyncio.runners: 3.7-
7070
asyncio.staggered: 3.8-
7171
asyncio.taskgroups: 3.11-
7272
asyncio.threads: 3.9-
73+
asyncio.timeouts: 3.11-
7374
asyncio.trsock: 3.8-
7475
asyncore: 2.7-
7576
atexit: 2.7-

mypy/typeshed/stdlib/__future__.pyi

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,18 @@ if sys.version_info >= (3, 7):
2121

2222
all_feature_names: list[str] # undocumented
2323

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

mypy/typeshed/stdlib/_ast.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ class Tuple(expr):
415415
__match_args__ = ("elts", "ctx")
416416
elts: list[expr]
417417
ctx: expr_context
418+
if sys.version_info >= (3, 9):
419+
dims: list[expr]
418420

419421
class expr_context(AST): ...
420422

mypy/typeshed/stdlib/_codecs.pyi

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,71 @@
11
import codecs
22
import sys
33
from collections.abc import Callable
4-
from typing import Any
5-
from typing_extensions import TypeAlias
4+
from typing import overload
5+
from typing_extensions import Literal, TypeAlias
66

77
# This type is not exposed; it is defined in unicodeobject.c
88
class _EncodingMap:
99
def size(self) -> int: ...
1010

1111
_MapT: TypeAlias = dict[int, int] | _EncodingMap
12-
_Handler: TypeAlias = Callable[[Exception], tuple[str, int]]
12+
_Handler: TypeAlias = Callable[[UnicodeError], tuple[str | bytes, int]]
13+
_SearchFunction: TypeAlias = Callable[[str], codecs.CodecInfo | None]
14+
15+
def register(__search_function: _SearchFunction) -> None: ...
16+
17+
if sys.version_info >= (3, 10):
18+
def unregister(__search_function: _SearchFunction) -> None: ...
1319

14-
def register(__search_function: Callable[[str], Any]) -> None: ...
1520
def register_error(__errors: str, __handler: _Handler) -> None: ...
16-
def lookup(__encoding: str) -> codecs.CodecInfo: ...
1721
def lookup_error(__name: str) -> _Handler: ...
18-
def decode(obj: Any, encoding: str = ..., errors: str | None = ...) -> Any: ...
19-
def encode(obj: Any, encoding: str = ..., errors: str | None = ...) -> Any: ...
22+
23+
# The type ignore on `encode` and `decode` is to avoid issues with overlapping overloads, for more details, see #300
24+
# https://docs.python.org/3/library/codecs.html#binary-transforms
25+
_BytesToBytesEncoding: TypeAlias = Literal[
26+
"base64",
27+
"base_64",
28+
"base64_codec",
29+
"bz2",
30+
"bz2_codec",
31+
"hex",
32+
"hex_codec",
33+
"quopri",
34+
"quotedprintable",
35+
"quoted_printable",
36+
"quopri_codec",
37+
"uu",
38+
"uu_codec",
39+
"zip",
40+
"zlib",
41+
"zlib_codec",
42+
]
43+
# https://docs.python.org/3/library/codecs.html#text-transforms
44+
_StrToStrEncoding: TypeAlias = Literal["rot13", "rot_13"]
45+
46+
@overload
47+
def encode(obj: bytes, encoding: _BytesToBytesEncoding, errors: str = ...) -> bytes: ...
48+
@overload
49+
def encode(obj: str, encoding: _StrToStrEncoding, errors: str = ...) -> str: ... # type: ignore[misc]
50+
@overload
51+
def encode(obj: str, encoding: str = ..., errors: str = ...) -> bytes: ...
52+
@overload
53+
def decode(obj: bytes, encoding: _BytesToBytesEncoding, errors: str = ...) -> bytes: ... # type: ignore[misc]
54+
@overload
55+
def decode(obj: str, encoding: _StrToStrEncoding, errors: str = ...) -> str: ...
56+
57+
# these are documented as text encodings but in practice they also accept str as input
58+
@overload
59+
def decode(
60+
obj: str, encoding: Literal["unicode_escape", "unicode-escape", "raw_unicode_escape", "raw-unicode-escape"], errors: str = ...
61+
) -> str: ...
62+
63+
# hex is officially documented as a bytes to bytes encoding, but it appears to also work with str
64+
@overload
65+
def decode(obj: str, encoding: Literal["hex", "hex_codec"], errors: str = ...) -> bytes: ...
66+
@overload
67+
def decode(obj: bytes, encoding: str = ..., errors: str = ...) -> str: ...
68+
def lookup(__encoding: str) -> codecs.CodecInfo: ...
2069
def charmap_build(__map: str) -> _MapT: ...
2170
def ascii_decode(__data: bytes, __errors: str | None = ...) -> tuple[str, int]: ...
2271
def ascii_encode(__str: str, __errors: str | None = ...) -> tuple[bytes, int]: ...

mypy/typeshed/stdlib/_dummy_thread.pyi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import sys
12
from collections.abc import Callable
23
from types import TracebackType
34
from typing import Any, NoReturn
45

6+
__all__ = ["error", "start_new_thread", "exit", "get_ident", "allocate_lock", "interrupt_main", "LockType"]
7+
8+
if sys.version_info >= (3, 7):
9+
__all__ += ["RLock"]
10+
511
TIMEOUT_MAX: int
612
error = RuntimeError
713

@@ -20,4 +26,8 @@ class LockType:
2026
def release(self) -> bool: ...
2127
def locked(self) -> bool: ...
2228

29+
if sys.version_info >= (3, 7):
30+
class RLock(LockType):
31+
def release(self) -> None: ... # type: ignore[override]
32+
2333
def interrupt_main() -> None: ...

mypy/typeshed/stdlib/_dummy_threading.pyi

Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,32 @@ _TF: TypeAlias = Callable[[FrameType, str, Any], Callable[..., Any] | None]
1010
_PF: TypeAlias = Callable[[FrameType, str, Any], None]
1111
_T = TypeVar("_T")
1212

13+
__all__ = [
14+
"get_ident",
15+
"active_count",
16+
"Condition",
17+
"current_thread",
18+
"enumerate",
19+
"main_thread",
20+
"TIMEOUT_MAX",
21+
"Event",
22+
"Lock",
23+
"RLock",
24+
"Semaphore",
25+
"BoundedSemaphore",
26+
"Thread",
27+
"Barrier",
28+
"BrokenBarrierError",
29+
"Timer",
30+
"ThreadError",
31+
"setprofile",
32+
"settrace",
33+
"local",
34+
"stack_size",
35+
]
36+
1337
if sys.version_info >= (3, 8):
14-
__all__ = [
15-
"get_ident",
16-
"active_count",
17-
"Condition",
18-
"current_thread",
19-
"enumerate",
20-
"main_thread",
21-
"TIMEOUT_MAX",
22-
"Event",
23-
"Lock",
24-
"RLock",
25-
"Semaphore",
26-
"BoundedSemaphore",
27-
"Thread",
28-
"Barrier",
29-
"BrokenBarrierError",
30-
"Timer",
31-
"ThreadError",
32-
"setprofile",
33-
"settrace",
34-
"local",
35-
"stack_size",
36-
"excepthook",
37-
"ExceptHookArgs",
38-
]
39-
else:
40-
__all__ = [
41-
"get_ident",
42-
"active_count",
43-
"Condition",
44-
"current_thread",
45-
"enumerate",
46-
"main_thread",
47-
"TIMEOUT_MAX",
48-
"Event",
49-
"Lock",
50-
"RLock",
51-
"Semaphore",
52-
"BoundedSemaphore",
53-
"Thread",
54-
"Barrier",
55-
"BrokenBarrierError",
56-
"Timer",
57-
"ThreadError",
58-
"setprofile",
59-
"settrace",
60-
"local",
61-
"stack_size",
62-
]
38+
__all__ += ["ExceptHookArgs", "excepthook"]
6339

6440
def active_count() -> int: ...
6541
def current_thread() -> Thread: ...

mypy/typeshed/stdlib/_imp.pyi

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
import sys
22
import types
3+
from _typeshed import ReadableBuffer
34
from importlib.machinery import ModuleSpec
45
from typing import Any
56

67
if sys.version_info >= (3, 7):
78
check_hash_based_pycs: str
9+
def source_hash(key: int, source: ReadableBuffer) -> bytes: ...
810

911
def create_builtin(__spec: ModuleSpec) -> types.ModuleType: ...
1012
def create_dynamic(__spec: ModuleSpec, __file: Any = ...) -> types.ModuleType: ...
1113
def acquire_lock() -> None: ...
1214
def exec_builtin(__mod: types.ModuleType) -> int: ...
1315
def exec_dynamic(__mod: types.ModuleType) -> int: ...
1416
def extension_suffixes() -> list[str]: ...
15-
def get_frozen_object(__name: str) -> types.CodeType: ...
1617
def init_frozen(__name: str) -> types.ModuleType: ...
1718
def is_builtin(__name: str) -> int: ...
1819
def is_frozen(__name: str) -> bool: ...
1920
def is_frozen_package(__name: str) -> bool: ...
2021
def lock_held() -> bool: ...
2122
def release_lock() -> None: ...
23+
24+
if sys.version_info >= (3, 11):
25+
def find_frozen(__name: str, *, withdata: bool = ...) -> tuple[memoryview | None, bool, str | None] | None: ...
26+
def get_frozen_object(__name: str, __data: ReadableBuffer | None = ...) -> types.CodeType: ...
27+
28+
else:
29+
def get_frozen_object(__name: str) -> types.CodeType: ...

0 commit comments

Comments
 (0)