Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/_frozen_importlib_external.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ else:

MAGIC_NUMBER: bytes

def cache_from_source(path: str, debug_override: bool | None = None, *, optimization: Any | None = None) -> str: ...
def source_from_cache(path: str) -> str: ...
def cache_from_source(path: StrPath, debug_override: bool | None = None, *, optimization: Any | None = None) -> str: ...
def source_from_cache(path: StrPath) -> str: ...
def decode_source(source_bytes: ReadableBuffer) -> str: ...
def spec_from_file_location(
name: str,
Expand Down
25 changes: 23 additions & 2 deletions mypy/typeshed/stdlib/codecs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ from _codecs import *
from _typeshed import ReadableBuffer
from abc import abstractmethod
from collections.abc import Callable, Generator, Iterable
from typing import Any, BinaryIO, ClassVar, Final, Literal, Protocol, TextIO
from typing_extensions import Self
from typing import Any, BinaryIO, ClassVar, Final, Literal, Protocol, TextIO, overload
from typing_extensions import Self, TypeAlias

__all__ = [
"register",
Expand Down Expand Up @@ -58,6 +58,21 @@ BOM32_LE: Final = b"\xff\xfe"
BOM64_BE: Final = b"\x00\x00\xfe\xff"
BOM64_LE: Final = b"\xff\xfe\x00\x00"

_BufferedEncoding: TypeAlias = Literal[
"idna",
"raw-unicode-escape",
"unicode-escape",
"utf-16",
"utf-16-be",
"utf-16-le",
"utf-32",
"utf-32-be",
"utf-32-le",
"utf-7",
"utf-8",
"utf-8-sig",
]

class _WritableStream(Protocol):
def write(self, data: bytes, /) -> object: ...
def seek(self, offset: int, whence: int, /) -> object: ...
Expand Down Expand Up @@ -94,6 +109,9 @@ class _IncrementalEncoder(Protocol):
class _IncrementalDecoder(Protocol):
def __call__(self, errors: str = ...) -> IncrementalDecoder: ...

class _BufferedIncrementalDecoder(Protocol):
def __call__(self, errors: str = ...) -> BufferedIncrementalDecoder: ...

class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]):
_is_text_encoding: bool
@property
Expand Down Expand Up @@ -125,6 +143,9 @@ class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]):
def getencoder(encoding: str) -> _Encoder: ...
def getdecoder(encoding: str) -> _Decoder: ...
def getincrementalencoder(encoding: str) -> _IncrementalEncoder: ...
@overload
def getincrementaldecoder(encoding: _BufferedEncoding) -> _BufferedIncrementalDecoder: ...
@overload
def getincrementaldecoder(encoding: str) -> _IncrementalDecoder: ...
def getreader(encoding: str) -> _StreamReader: ...
def getwriter(encoding: str) -> _StreamWriter: ...
Expand Down
14 changes: 7 additions & 7 deletions mypy/typeshed/stdlib/compileall.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if sys.version_info >= (3, 10):
prependdir: StrPath | None = None,
limit_sl_dest: StrPath | None = None,
hardlink_dupes: bool = False,
) -> int: ...
) -> bool: ...
def compile_file(
fullname: StrPath,
ddir: StrPath | None = None,
Expand All @@ -40,7 +40,7 @@ if sys.version_info >= (3, 10):
prependdir: StrPath | None = None,
limit_sl_dest: StrPath | None = None,
hardlink_dupes: bool = False,
) -> int: ...
) -> bool: ...

elif sys.version_info >= (3, 9):
def compile_dir(
Expand All @@ -59,7 +59,7 @@ elif sys.version_info >= (3, 9):
prependdir: StrPath | None = None,
limit_sl_dest: StrPath | None = None,
hardlink_dupes: bool = False,
) -> int: ...
) -> bool: ...
def compile_file(
fullname: StrPath,
ddir: StrPath | None = None,
Expand All @@ -74,7 +74,7 @@ elif sys.version_info >= (3, 9):
prependdir: StrPath | None = None,
limit_sl_dest: StrPath | None = None,
hardlink_dupes: bool = False,
) -> int: ...
) -> bool: ...

else:
def compile_dir(
Expand All @@ -88,7 +88,7 @@ else:
optimize: int = -1,
workers: int = 1,
invalidation_mode: PycInvalidationMode | None = None,
) -> int: ...
) -> bool: ...
def compile_file(
fullname: StrPath,
ddir: StrPath | None = None,
Expand All @@ -98,7 +98,7 @@ else:
legacy: bool = False,
optimize: int = -1,
invalidation_mode: PycInvalidationMode | None = None,
) -> int: ...
) -> bool: ...

def compile_path(
skip_curdir: bool = ...,
Expand All @@ -108,4 +108,4 @@ def compile_path(
legacy: bool = False,
optimize: int = -1,
invalidation_mode: PycInvalidationMode | None = None,
) -> int: ...
) -> bool: ...
34 changes: 28 additions & 6 deletions mypy/typeshed/stdlib/email/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections.abc import Callable
from email.message import Message
from email.policy import Policy
from typing import IO
from email.policy import Policy, _MessageT
from typing import IO, overload
from typing_extensions import TypeAlias

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

def message_from_string(s: str, _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ...
def message_from_bytes(s: bytes | bytearray, _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ...
def message_from_file(fp: IO[str], _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ...
def message_from_binary_file(fp: IO[bytes], _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> Message: ...
@overload
def message_from_string(s: str) -> Message: ...
@overload
def message_from_string(s: str, _class: Callable[[], _MessageT]) -> _MessageT: ...
@overload
def message_from_string(s: str, _class: Callable[[], _MessageT] = ..., *, policy: Policy[_MessageT]) -> _MessageT: ...
@overload
def message_from_bytes(s: bytes | bytearray) -> Message: ...
@overload
def message_from_bytes(s: bytes | bytearray, _class: Callable[[], _MessageT]) -> _MessageT: ...
@overload
def message_from_bytes(
s: bytes | bytearray, _class: Callable[[], _MessageT] = ..., *, policy: Policy[_MessageT]
) -> _MessageT: ...
@overload
def message_from_file(fp: IO[str]) -> Message: ...
@overload
def message_from_file(fp: IO[str], _class: Callable[[], _MessageT]) -> _MessageT: ...
@overload
def message_from_file(fp: IO[str], _class: Callable[[], _MessageT] = ..., *, policy: Policy[_MessageT]) -> _MessageT: ...
@overload
def message_from_binary_file(fp: IO[bytes]) -> Message: ...
@overload
def message_from_binary_file(fp: IO[bytes], _class: Callable[[], _MessageT]) -> _MessageT: ...
@overload
def message_from_binary_file(fp: IO[bytes], _class: Callable[[], _MessageT] = ..., *, policy: Policy[_MessageT]) -> _MessageT: ...
5 changes: 2 additions & 3 deletions mypy/typeshed/stdlib/email/mime/message.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from email.message import Message
from email.mime.nonmultipart import MIMENonMultipart
from email.policy import Policy
from email.policy import Policy, _MessageT

__all__ = ["MIMEMessage"]

class MIMEMessage(MIMENonMultipart):
def __init__(self, _msg: Message, _subtype: str = "rfc822", *, policy: Policy | None = None) -> None: ...
def __init__(self, _msg: _MessageT, _subtype: str = "rfc822", *, policy: Policy[_MessageT] | None = None) -> None: ...
7 changes: 3 additions & 4 deletions mypy/typeshed/stdlib/email/mime/multipart.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from collections.abc import Sequence
from email import _ParamsType
from email.message import Message
from email.mime.base import MIMEBase
from email.policy import Policy
from email.policy import Policy, _MessageT

__all__ = ["MIMEMultipart"]

Expand All @@ -11,8 +10,8 @@ class MIMEMultipart(MIMEBase):
self,
_subtype: str = "mixed",
boundary: str | None = None,
_subparts: Sequence[Message] | None = None,
_subparts: Sequence[_MessageT] | None = None,
*,
policy: Policy | None = None,
policy: Policy[_MessageT] | None = None,
**_params: _ParamsType,
) -> None: ...