Skip to content

Commit e93f06c

Browse files
authored
Sync typeshed in preparation for release (#18741)
1 parent 915c3c5 commit e93f06c

File tree

6 files changed

+65
-24
lines changed

6 files changed

+65
-24
lines changed

mypy/typeshed/stdlib/_frozen_importlib_external.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ else:
2626

2727
MAGIC_NUMBER: bytes
2828

29-
def cache_from_source(path: str, debug_override: bool | None = None, *, optimization: Any | None = None) -> str: ...
30-
def source_from_cache(path: str) -> str: ...
29+
def cache_from_source(path: StrPath, debug_override: bool | None = None, *, optimization: Any | None = None) -> str: ...
30+
def source_from_cache(path: StrPath) -> str: ...
3131
def decode_source(source_bytes: ReadableBuffer) -> str: ...
3232
def spec_from_file_location(
3333
name: str,

mypy/typeshed/stdlib/codecs.pyi

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ from _codecs import *
33
from _typeshed import ReadableBuffer
44
from abc import abstractmethod
55
from collections.abc import Callable, Generator, Iterable
6-
from typing import Any, BinaryIO, ClassVar, Final, Literal, Protocol, TextIO
7-
from typing_extensions import Self
6+
from typing import Any, BinaryIO, ClassVar, Final, Literal, Protocol, TextIO, overload
7+
from typing_extensions import Self, TypeAlias
88

99
__all__ = [
1010
"register",
@@ -58,6 +58,21 @@ BOM32_LE: Final = b"\xff\xfe"
5858
BOM64_BE: Final = b"\x00\x00\xfe\xff"
5959
BOM64_LE: Final = b"\xff\xfe\x00\x00"
6060

61+
_BufferedEncoding: TypeAlias = Literal[
62+
"idna",
63+
"raw-unicode-escape",
64+
"unicode-escape",
65+
"utf-16",
66+
"utf-16-be",
67+
"utf-16-le",
68+
"utf-32",
69+
"utf-32-be",
70+
"utf-32-le",
71+
"utf-7",
72+
"utf-8",
73+
"utf-8-sig",
74+
]
75+
6176
class _WritableStream(Protocol):
6277
def write(self, data: bytes, /) -> object: ...
6378
def seek(self, offset: int, whence: int, /) -> object: ...
@@ -94,6 +109,9 @@ class _IncrementalEncoder(Protocol):
94109
class _IncrementalDecoder(Protocol):
95110
def __call__(self, errors: str = ...) -> IncrementalDecoder: ...
96111

112+
class _BufferedIncrementalDecoder(Protocol):
113+
def __call__(self, errors: str = ...) -> BufferedIncrementalDecoder: ...
114+
97115
class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]):
98116
_is_text_encoding: bool
99117
@property
@@ -125,6 +143,9 @@ class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]):
125143
def getencoder(encoding: str) -> _Encoder: ...
126144
def getdecoder(encoding: str) -> _Decoder: ...
127145
def getincrementalencoder(encoding: str) -> _IncrementalEncoder: ...
146+
@overload
147+
def getincrementaldecoder(encoding: _BufferedEncoding) -> _BufferedIncrementalDecoder: ...
148+
@overload
128149
def getincrementaldecoder(encoding: str) -> _IncrementalDecoder: ...
129150
def getreader(encoding: str) -> _StreamReader: ...
130151
def getwriter(encoding: str) -> _StreamWriter: ...

mypy/typeshed/stdlib/compileall.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if sys.version_info >= (3, 10):
2525
prependdir: StrPath | None = None,
2626
limit_sl_dest: StrPath | None = None,
2727
hardlink_dupes: bool = False,
28-
) -> int: ...
28+
) -> bool: ...
2929
def compile_file(
3030
fullname: StrPath,
3131
ddir: StrPath | None = None,
@@ -40,7 +40,7 @@ if sys.version_info >= (3, 10):
4040
prependdir: StrPath | None = None,
4141
limit_sl_dest: StrPath | None = None,
4242
hardlink_dupes: bool = False,
43-
) -> int: ...
43+
) -> bool: ...
4444

4545
elif sys.version_info >= (3, 9):
4646
def compile_dir(
@@ -59,7 +59,7 @@ elif sys.version_info >= (3, 9):
5959
prependdir: StrPath | None = None,
6060
limit_sl_dest: StrPath | None = None,
6161
hardlink_dupes: bool = False,
62-
) -> int: ...
62+
) -> bool: ...
6363
def compile_file(
6464
fullname: StrPath,
6565
ddir: StrPath | None = None,
@@ -74,7 +74,7 @@ elif sys.version_info >= (3, 9):
7474
prependdir: StrPath | None = None,
7575
limit_sl_dest: StrPath | None = None,
7676
hardlink_dupes: bool = False,
77-
) -> int: ...
77+
) -> bool: ...
7878

7979
else:
8080
def compile_dir(
@@ -88,7 +88,7 @@ else:
8888
optimize: int = -1,
8989
workers: int = 1,
9090
invalidation_mode: PycInvalidationMode | None = None,
91-
) -> int: ...
91+
) -> bool: ...
9292
def compile_file(
9393
fullname: StrPath,
9494
ddir: StrPath | None = None,
@@ -98,7 +98,7 @@ else:
9898
legacy: bool = False,
9999
optimize: int = -1,
100100
invalidation_mode: PycInvalidationMode | None = None,
101-
) -> int: ...
101+
) -> bool: ...
102102

103103
def compile_path(
104104
skip_curdir: bool = ...,
@@ -108,4 +108,4 @@ def compile_path(
108108
legacy: bool = False,
109109
optimize: int = -1,
110110
invalidation_mode: PycInvalidationMode | None = None,
111-
) -> int: ...
111+
) -> bool: ...

mypy/typeshed/stdlib/email/__init__.pyi

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections.abc import Callable
22
from email.message import Message
3-
from email.policy import Policy
4-
from typing import IO
3+
from email.policy import Policy, _MessageT
4+
from typing import IO, overload
55
from typing_extensions import TypeAlias
66

77
# At runtime, listing submodules in __all__ without them being imported is
@@ -31,7 +31,29 @@ __all__ = [ # noqa: F822 # Undefined names in __all__
3131
_ParamType: TypeAlias = str | tuple[str | None, str | None, str] # noqa: Y047
3232
_ParamsType: TypeAlias = str | None | tuple[str, str | None, str] # noqa: Y047
3333

34-
def message_from_string(s: str, _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ...
35-
def message_from_bytes(s: bytes | bytearray, _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ...
36-
def message_from_file(fp: IO[str], _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ...
37-
def message_from_binary_file(fp: IO[bytes], _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ...
34+
@overload
35+
def message_from_string(s: str) -> Message: ...
36+
@overload
37+
def message_from_string(s: str, _class: Callable[[], _MessageT]) -> _MessageT: ...
38+
@overload
39+
def message_from_string(s: str, _class: Callable[[], _MessageT] = ..., *, policy: Policy[_MessageT]) -> _MessageT: ...
40+
@overload
41+
def message_from_bytes(s: bytes | bytearray) -> Message: ...
42+
@overload
43+
def message_from_bytes(s: bytes | bytearray, _class: Callable[[], _MessageT]) -> _MessageT: ...
44+
@overload
45+
def message_from_bytes(
46+
s: bytes | bytearray, _class: Callable[[], _MessageT] = ..., *, policy: Policy[_MessageT]
47+
) -> _MessageT: ...
48+
@overload
49+
def message_from_file(fp: IO[str]) -> Message: ...
50+
@overload
51+
def message_from_file(fp: IO[str], _class: Callable[[], _MessageT]) -> _MessageT: ...
52+
@overload
53+
def message_from_file(fp: IO[str], _class: Callable[[], _MessageT] = ..., *, policy: Policy[_MessageT]) -> _MessageT: ...
54+
@overload
55+
def message_from_binary_file(fp: IO[bytes]) -> Message: ...
56+
@overload
57+
def message_from_binary_file(fp: IO[bytes], _class: Callable[[], _MessageT]) -> _MessageT: ...
58+
@overload
59+
def message_from_binary_file(fp: IO[bytes], _class: Callable[[], _MessageT] = ..., *, policy: Policy[_MessageT]) -> _MessageT: ...
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from email.message import Message
21
from email.mime.nonmultipart import MIMENonMultipart
3-
from email.policy import Policy
2+
from email.policy import Policy, _MessageT
43

54
__all__ = ["MIMEMessage"]
65

76
class MIMEMessage(MIMENonMultipart):
8-
def __init__(self, _msg: Message, _subtype: str = "rfc822", *, policy: Policy | None = None) -> None: ...
7+
def __init__(self, _msg: _MessageT, _subtype: str = "rfc822", *, policy: Policy[_MessageT] | None = None) -> None: ...
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from collections.abc import Sequence
22
from email import _ParamsType
3-
from email.message import Message
43
from email.mime.base import MIMEBase
5-
from email.policy import Policy
4+
from email.policy import Policy, _MessageT
65

76
__all__ = ["MIMEMultipart"]
87

@@ -11,8 +10,8 @@ class MIMEMultipart(MIMEBase):
1110
self,
1211
_subtype: str = "mixed",
1312
boundary: str | None = None,
14-
_subparts: Sequence[Message] | None = None,
13+
_subparts: Sequence[_MessageT] | None = None,
1514
*,
16-
policy: Policy | None = None,
15+
policy: Policy[_MessageT] | None = None,
1716
**_params: _ParamsType,
1817
) -> None: ...

0 commit comments

Comments
 (0)