From 31b9085e90750a4ddf970549410434ea458414d2 Mon Sep 17 00:00:00 2001
From: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Date: Thu, 5 Dec 2024 20:37:26 +0100
Subject: [PATCH 1/4] Sync typeshed
Source commit:
https://github.com/python/typeshed/commit/633a4d73f257d3d1e73f8fdae24f2ddcca724399
---
mypy/typeshed/stdlib/VERSIONS | 1 +
mypy/typeshed/stdlib/_ctypes.pyi | 6 +-
mypy/typeshed/stdlib/_dummy_threading.pyi | 146 ++-------------
mypy/typeshed/stdlib/_pickle.pyi | 108 +++++++++++
mypy/typeshed/stdlib/_socket.pyi | 4 +-
mypy/typeshed/stdlib/_tkinter.pyi | 37 ++--
mypy/typeshed/stdlib/argparse.pyi | 36 ++--
mypy/typeshed/stdlib/builtins.pyi | 102 ++++++++++-
mypy/typeshed/stdlib/codeop.pyi | 6 +-
.../stdlib/concurrent/futures/process.pyi | 14 +-
mypy/typeshed/stdlib/gzip.pyi | 10 +-
.../stdlib/multiprocessing/reduction.pyi | 2 +-
mypy/typeshed/stdlib/pickle.pyi | 137 +++++---------
mypy/typeshed/stdlib/pickletools.pyi | 9 +-
mypy/typeshed/stdlib/select.pyi | 6 +-
mypy/typeshed/stdlib/selectors.pyi | 2 +-
mypy/typeshed/stdlib/socket.pyi | 10 +-
mypy/typeshed/stdlib/sys/__init__.pyi | 2 +-
mypy/typeshed/stdlib/tarfile.pyi | 30 ++-
mypy/typeshed/stdlib/tkinter/__init__.pyi | 171 +++++++++++++++++-
mypy/typeshed/stdlib/token.pyi | 2 +-
mypy/typeshed/stdlib/tokenize.pyi | 2 +-
mypy/typeshed/stdlib/typing.pyi | 2 +-
mypy/typeshed/stdlib/weakref.pyi | 8 +-
mypy/typeshed/stdlib/xml/sax/expatreader.pyi | 53 ++++++
.../zipfile/{_path.pyi => _path/__init__.pyi} | 0
mypy/typeshed/stdlib/zipfile/_path/glob.pyi | 22 +++
27 files changed, 648 insertions(+), 280 deletions(-)
create mode 100644 mypy/typeshed/stdlib/_pickle.pyi
create mode 100644 mypy/typeshed/stdlib/xml/sax/expatreader.pyi
rename mypy/typeshed/stdlib/zipfile/{_path.pyi => _path/__init__.pyi} (100%)
create mode 100644 mypy/typeshed/stdlib/zipfile/_path/glob.pyi
diff --git a/mypy/typeshed/stdlib/VERSIONS b/mypy/typeshed/stdlib/VERSIONS
index 7ff14c55d3a8..3c6898dc1a77 100644
--- a/mypy/typeshed/stdlib/VERSIONS
+++ b/mypy/typeshed/stdlib/VERSIONS
@@ -57,6 +57,7 @@ _msi: 3.0-3.12
_multibytecodec: 3.0-
_operator: 3.4-
_osx_support: 3.0-
+_pickle: 3.0-
_posixsubprocess: 3.2-
_py_abc: 3.7-
_pydecimal: 3.5-
diff --git a/mypy/typeshed/stdlib/_ctypes.pyi b/mypy/typeshed/stdlib/_ctypes.pyi
index ecb07a29bb75..1f3f8f38802b 100644
--- a/mypy/typeshed/stdlib/_ctypes.pyi
+++ b/mypy/typeshed/stdlib/_ctypes.pyi
@@ -286,7 +286,11 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType):
def _type_(self) -> type[_CT]: ...
@_type_.setter
def _type_(self, value: type[_CT]) -> None: ...
- raw: bytes # Note: only available if _CT == c_char
+ # Note: only available if _CT == c_char
+ @property
+ def raw(self) -> bytes: ...
+ @raw.setter
+ def raw(self, value: ReadableBuffer) -> None: ...
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
# TODO These methods cannot be annotated correctly at the moment.
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT
diff --git a/mypy/typeshed/stdlib/_dummy_threading.pyi b/mypy/typeshed/stdlib/_dummy_threading.pyi
index 21d1d1921c0e..1b66fb414d7a 100644
--- a/mypy/typeshed/stdlib/_dummy_threading.pyi
+++ b/mypy/typeshed/stdlib/_dummy_threading.pyi
@@ -1,11 +1,23 @@
-import sys
-from _thread import _excepthook, _ExceptHookArgs
+from _threading_local import local as local
from _typeshed import ProfileFunction, TraceFunction
-from collections.abc import Callable, Iterable, Mapping
-from types import TracebackType
-from typing import Any, TypeVar
-
-_T = TypeVar("_T")
+from threading import (
+ TIMEOUT_MAX as TIMEOUT_MAX,
+ Barrier as Barrier,
+ BoundedSemaphore as BoundedSemaphore,
+ BrokenBarrierError as BrokenBarrierError,
+ Condition as Condition,
+ Event as Event,
+ ExceptHookArgs as ExceptHookArgs,
+ Lock as Lock,
+ RLock as RLock,
+ Semaphore as Semaphore,
+ Thread as Thread,
+ ThreadError as ThreadError,
+ Timer as Timer,
+ _DummyThread as _DummyThread,
+ _RLock as _RLock,
+ excepthook as excepthook,
+)
__all__ = [
"get_ident",
@@ -42,123 +54,3 @@ def main_thread() -> Thread: ...
def settrace(func: TraceFunction) -> None: ...
def setprofile(func: ProfileFunction | None) -> None: ...
def stack_size(size: int | None = None) -> int: ...
-
-TIMEOUT_MAX: float
-
-class ThreadError(Exception): ...
-
-class local:
- def __getattribute__(self, name: str) -> Any: ...
- def __setattr__(self, name: str, value: Any) -> None: ...
- def __delattr__(self, name: str) -> None: ...
-
-class Thread:
- name: str
- daemon: bool
- @property
- def ident(self) -> int | None: ...
- def __init__(
- self,
- group: None = None,
- target: Callable[..., object] | None = None,
- name: str | None = None,
- args: Iterable[Any] = (),
- kwargs: Mapping[str, Any] | None = None,
- *,
- daemon: bool | None = None,
- ) -> None: ...
- def start(self) -> None: ...
- def run(self) -> None: ...
- def join(self, timeout: float | None = None) -> None: ...
- def getName(self) -> str: ...
- def setName(self, name: str) -> None: ...
- @property
- def native_id(self) -> int | None: ... # only available on some platforms
- def is_alive(self) -> bool: ...
- if sys.version_info < (3, 9):
- def isAlive(self) -> bool: ...
-
- def isDaemon(self) -> bool: ...
- def setDaemon(self, daemonic: bool) -> None: ...
-
-class _DummyThread(Thread): ...
-
-class Lock:
- def __enter__(self) -> bool: ...
- def __exit__(
- self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
- ) -> bool | None: ...
- def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ...
- def release(self) -> None: ...
- def locked(self) -> bool: ...
-
-class _RLock:
- def __enter__(self) -> bool: ...
- def __exit__(
- self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
- ) -> bool | None: ...
- def acquire(self, blocking: bool = True, timeout: float = -1) -> bool: ...
- def release(self) -> None: ...
-
-RLock = _RLock
-
-class Condition:
- def __init__(self, lock: Lock | _RLock | None = None) -> None: ...
- def __enter__(self) -> bool: ...
- def __exit__(
- self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
- ) -> bool | None: ...
- def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ...
- def release(self) -> None: ...
- def wait(self, timeout: float | None = None) -> bool: ...
- def wait_for(self, predicate: Callable[[], _T], timeout: float | None = None) -> _T: ...
- def notify(self, n: int = 1) -> None: ...
- def notify_all(self) -> None: ...
- def notifyAll(self) -> None: ...
-
-class Semaphore:
- def __init__(self, value: int = 1) -> None: ...
- def __exit__(
- self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
- ) -> bool | None: ...
- def acquire(self, blocking: bool = True, timeout: float | None = None) -> bool: ...
- def __enter__(self, blocking: bool = True, timeout: float | None = None) -> bool: ...
- if sys.version_info >= (3, 9):
- def release(self, n: int = ...) -> None: ...
- else:
- def release(self) -> None: ...
-
-class BoundedSemaphore(Semaphore): ...
-
-class Event:
- def is_set(self) -> bool: ...
- def set(self) -> None: ...
- def clear(self) -> None: ...
- def wait(self, timeout: float | None = None) -> bool: ...
-
-excepthook = _excepthook
-ExceptHookArgs = _ExceptHookArgs
-
-class Timer(Thread):
- def __init__(
- self,
- interval: float,
- function: Callable[..., object],
- args: Iterable[Any] | None = None,
- kwargs: Mapping[str, Any] | None = None,
- ) -> None: ...
- def cancel(self) -> None: ...
-
-class Barrier:
- @property
- def parties(self) -> int: ...
- @property
- def n_waiting(self) -> int: ...
- @property
- def broken(self) -> bool: ...
- def __init__(self, parties: int, action: Callable[[], None] | None = None, timeout: float | None = None) -> None: ...
- def wait(self, timeout: float | None = None) -> int: ...
- def reset(self) -> None: ...
- def abort(self) -> None: ...
-
-class BrokenBarrierError(RuntimeError): ...
diff --git a/mypy/typeshed/stdlib/_pickle.pyi b/mypy/typeshed/stdlib/_pickle.pyi
new file mode 100644
index 000000000000..5566f0f65d6e
--- /dev/null
+++ b/mypy/typeshed/stdlib/_pickle.pyi
@@ -0,0 +1,108 @@
+import sys
+from _typeshed import ReadableBuffer, SupportsWrite
+from collections.abc import Callable, Iterable, Iterator, Mapping
+from pickle import PickleBuffer as PickleBuffer
+from typing import Any, Protocol, type_check_only
+from typing_extensions import TypeAlias
+
+class _ReadableFileobj(Protocol):
+ def read(self, n: int, /) -> bytes: ...
+ def readline(self) -> bytes: ...
+
+_BufferCallback: TypeAlias = Callable[[PickleBuffer], Any] | None
+
+_ReducedType: TypeAlias = (
+ str
+ | tuple[Callable[..., Any], tuple[Any, ...]]
+ | tuple[Callable[..., Any], tuple[Any, ...], Any]
+ | tuple[Callable[..., Any], tuple[Any, ...], Any, Iterator[Any] | None]
+ | tuple[Callable[..., Any], tuple[Any, ...], Any, Iterator[Any] | None, Iterator[Any] | None]
+)
+
+def dump(
+ obj: Any,
+ file: SupportsWrite[bytes],
+ protocol: int | None = None,
+ *,
+ fix_imports: bool = True,
+ buffer_callback: _BufferCallback = None,
+) -> None: ...
+def dumps(
+ obj: Any, protocol: int | None = None, *, fix_imports: bool = True, buffer_callback: _BufferCallback = None
+) -> bytes: ...
+def load(
+ file: _ReadableFileobj,
+ *,
+ fix_imports: bool = True,
+ encoding: str = "ASCII",
+ errors: str = "strict",
+ buffers: Iterable[Any] | None = (),
+) -> Any: ...
+def loads(
+ data: ReadableBuffer,
+ /,
+ *,
+ fix_imports: bool = True,
+ encoding: str = "ASCII",
+ errors: str = "strict",
+ buffers: Iterable[Any] | None = (),
+) -> Any: ...
+
+class PickleError(Exception): ...
+class PicklingError(PickleError): ...
+class UnpicklingError(PickleError): ...
+
+@type_check_only
+class PicklerMemoProxy:
+ def clear(self, /) -> None: ...
+ def copy(self, /) -> dict[int, tuple[int, Any]]: ...
+
+class Pickler:
+ fast: bool
+ dispatch_table: Mapping[type, Callable[[Any], _ReducedType]]
+ reducer_override: Callable[[Any], Any]
+ bin: bool # undocumented
+ def __init__(
+ self,
+ file: SupportsWrite[bytes],
+ protocol: int | None = None,
+ *,
+ fix_imports: bool = True,
+ buffer_callback: _BufferCallback = None,
+ ) -> None: ...
+ @property
+ def memo(self) -> PicklerMemoProxy: ...
+ @memo.setter
+ def memo(self, value: PicklerMemoProxy | dict[int, tuple[int, Any]]) -> None: ...
+ def dump(self, obj: Any, /) -> None: ...
+ def clear_memo(self) -> None: ...
+ if sys.version_info >= (3, 13):
+ def persistent_id(self, obj: Any, /) -> Any: ...
+ else:
+ persistent_id: Callable[[Any], Any]
+
+@type_check_only
+class UnpicklerMemoProxy:
+ def clear(self, /) -> None: ...
+ def copy(self, /) -> dict[int, tuple[int, Any]]: ...
+
+class Unpickler:
+ def __init__(
+ self,
+ file: _ReadableFileobj,
+ *,
+ fix_imports: bool = True,
+ encoding: str = "ASCII",
+ errors: str = "strict",
+ buffers: Iterable[Any] | None = (),
+ ) -> None: ...
+ @property
+ def memo(self) -> UnpicklerMemoProxy: ...
+ @memo.setter
+ def memo(self, value: UnpicklerMemoProxy | dict[int, tuple[int, Any]]) -> None: ...
+ def load(self) -> Any: ...
+ def find_class(self, module_name: str, global_name: str, /) -> Any: ...
+ if sys.version_info >= (3, 13):
+ def persistent_load(self, pid: Any, /) -> Any: ...
+ else:
+ persistent_load: Callable[[Any], Any]
diff --git a/mypy/typeshed/stdlib/_socket.pyi b/mypy/typeshed/stdlib/_socket.pyi
index 36bc5c31c646..4cf71cbcadfa 100644
--- a/mypy/typeshed/stdlib/_socket.pyi
+++ b/mypy/typeshed/stdlib/_socket.pyi
@@ -78,8 +78,10 @@ if sys.platform == "win32":
SO_EXCLUSIVEADDRUSE: int
if sys.platform != "win32":
SO_REUSEPORT: int
+ if sys.platform != "darwin" or sys.version_info >= (3, 13):
+ SO_BINDTODEVICE: int
+
if sys.platform != "win32" and sys.platform != "darwin":
- SO_BINDTODEVICE: int
SO_DOMAIN: int
SO_MARK: int
SO_PASSCRED: int
diff --git a/mypy/typeshed/stdlib/_tkinter.pyi b/mypy/typeshed/stdlib/_tkinter.pyi
index 63b1e7ca7cb4..4206a2114f95 100644
--- a/mypy/typeshed/stdlib/_tkinter.pyi
+++ b/mypy/typeshed/stdlib/_tkinter.pyi
@@ -113,16 +113,31 @@ TK_VERSION: Final[str]
class TkttType:
def deletetimerhandler(self): ...
-def create(
- screenName: str | None = None,
- baseName: str = "",
- className: str = "Tk",
- interactive: bool = False,
- wantobjects: bool = False,
- wantTk: bool = True,
- sync: bool = False,
- use: str | None = None,
- /,
-): ...
+if sys.version_info >= (3, 13):
+ def create(
+ screenName: str | None = None,
+ baseName: str = "",
+ className: str = "Tk",
+ interactive: bool = False,
+ wantobjects: int = 0,
+ wantTk: bool = True,
+ sync: bool = False,
+ use: str | None = None,
+ /,
+ ): ...
+
+else:
+ def create(
+ screenName: str | None = None,
+ baseName: str = "",
+ className: str = "Tk",
+ interactive: bool = False,
+ wantobjects: bool = False,
+ wantTk: bool = True,
+ sync: bool = False,
+ use: str | None = None,
+ /,
+ ): ...
+
def getbusywaitinterval(): ...
def setbusywaitinterval(new_val, /): ...
diff --git a/mypy/typeshed/stdlib/argparse.pyi b/mypy/typeshed/stdlib/argparse.pyi
index 2526322ac8f6..365617077f09 100644
--- a/mypy/typeshed/stdlib/argparse.pyi
+++ b/mypy/typeshed/stdlib/argparse.pyi
@@ -182,30 +182,30 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
def add_subparsers(
self: _ArgumentParserT,
*,
- title: str = ...,
- description: str | None = ...,
- prog: str = ...,
+ title: str = "subcommands",
+ description: str | None = None,
+ prog: str | None = None,
action: type[Action] = ...,
option_string: str = ...,
- dest: str | None = ...,
- required: bool = ...,
- help: str | None = ...,
- metavar: str | None = ...,
+ dest: str | None = None,
+ required: bool = False,
+ help: str | None = None,
+ metavar: str | None = None,
) -> _SubParsersAction[_ArgumentParserT]: ...
@overload
def add_subparsers(
self,
*,
- title: str = ...,
- description: str | None = ...,
- prog: str = ...,
+ title: str = "subcommands",
+ description: str | None = None,
+ prog: str | None = None,
parser_class: type[_ArgumentParserT],
action: type[Action] = ...,
option_string: str = ...,
- dest: str | None = ...,
- required: bool = ...,
- help: str | None = ...,
- metavar: str | None = ...,
+ dest: str | None = None,
+ required: bool = False,
+ help: str | None = None,
+ metavar: str | None = None,
) -> _SubParsersAction[_ArgumentParserT]: ...
def print_usage(self, file: IO[str] | None = None) -> None: ...
def print_help(self, file: IO[str] | None = None) -> None: ...
@@ -237,7 +237,13 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
# undocumented
def _get_optional_actions(self) -> list[Action]: ...
def _get_positional_actions(self) -> list[Action]: ...
- def _parse_known_args(self, arg_strings: list[str], namespace: Namespace) -> tuple[Namespace, list[str]]: ...
+ if sys.version_info >= (3, 12):
+ def _parse_known_args(
+ self, arg_strings: list[str], namespace: Namespace, intermixed: bool
+ ) -> tuple[Namespace, list[str]]: ...
+ else:
+ def _parse_known_args(self, arg_strings: list[str], namespace: Namespace) -> tuple[Namespace, list[str]]: ...
+
def _read_args_from_files(self, arg_strings: list[str]) -> list[str]: ...
def _match_argument(self, action: Action, arg_strings_pattern: str) -> int: ...
def _match_arguments_partial(self, actions: Sequence[Action], arg_strings_pattern: str) -> list[int]: ...
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
index 1a4ca925168a..4c7467fc84c8 100644
--- a/mypy/typeshed/stdlib/builtins.pyi
+++ b/mypy/typeshed/stdlib/builtins.pyi
@@ -64,6 +64,7 @@ from typing import ( # noqa: Y022
from typing_extensions import ( # noqa: Y023
Concatenate,
Literal,
+ LiteralString,
ParamSpec,
Self,
TypeAlias,
@@ -441,16 +442,31 @@ class str(Sequence[str]):
def __new__(cls, object: object = ...) -> Self: ...
@overload
def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
+ @overload
+ def capitalize(self: LiteralString) -> LiteralString: ...
+ @overload
def capitalize(self) -> str: ... # type: ignore[misc]
+ @overload
+ def casefold(self: LiteralString) -> LiteralString: ...
+ @overload
def casefold(self) -> str: ... # type: ignore[misc]
+ @overload
+ def center(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
+ @overload
def center(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
def count(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
def endswith(
self, suffix: str | tuple[str, ...], start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
) -> bool: ...
+ @overload
+ def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
+ @overload
def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
def find(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
+ @overload
+ def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
+ @overload
def format(self, *args: object, **kwargs: object) -> str: ...
def format_map(self, mapping: _FormatMapMapping, /) -> str: ...
def index(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
@@ -466,35 +482,99 @@ class str(Sequence[str]):
def isspace(self) -> bool: ...
def istitle(self) -> bool: ...
def isupper(self) -> bool: ...
+ @overload
+ def join(self: LiteralString, iterable: Iterable[LiteralString], /) -> LiteralString: ...
+ @overload
def join(self, iterable: Iterable[str], /) -> str: ... # type: ignore[misc]
+ @overload
+ def ljust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
+ @overload
def ljust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
+ @overload
+ def lower(self: LiteralString) -> LiteralString: ...
+ @overload
def lower(self) -> str: ... # type: ignore[misc]
+ @overload
+ def lstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
+ @overload
def lstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
+ @overload
+ def partition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
+ @overload
def partition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
if sys.version_info >= (3, 13):
+ @overload
+ def replace(
+ self: LiteralString, old: LiteralString, new: LiteralString, /, count: SupportsIndex = -1
+ ) -> LiteralString: ...
+ @overload
def replace(self, old: str, new: str, /, count: SupportsIndex = -1) -> str: ... # type: ignore[misc]
else:
+ @overload
+ def replace(
+ self: LiteralString, old: LiteralString, new: LiteralString, count: SupportsIndex = -1, /
+ ) -> LiteralString: ...
+ @overload
def replace(self, old: str, new: str, count: SupportsIndex = -1, /) -> str: ... # type: ignore[misc]
if sys.version_info >= (3, 9):
+ @overload
+ def removeprefix(self: LiteralString, prefix: LiteralString, /) -> LiteralString: ...
+ @overload
def removeprefix(self, prefix: str, /) -> str: ... # type: ignore[misc]
+ @overload
+ def removesuffix(self: LiteralString, suffix: LiteralString, /) -> LiteralString: ...
+ @overload
def removesuffix(self, suffix: str, /) -> str: ... # type: ignore[misc]
def rfind(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
def rindex(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
+ @overload
+ def rjust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
+ @overload
def rjust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
+ @overload
+ def rpartition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
+ @overload
def rpartition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
+ @overload
+ def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
+ @overload
def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
+ @overload
+ def rstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
+ @overload
def rstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
+ @overload
+ def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
+ @overload
def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
+ @overload
+ def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ...
+ @overload
def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
def startswith(
self, prefix: str | tuple[str, ...], start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
) -> bool: ...
+ @overload
+ def strip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
+ @overload
def strip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
+ @overload
+ def swapcase(self: LiteralString) -> LiteralString: ...
+ @overload
def swapcase(self) -> str: ... # type: ignore[misc]
+ @overload
+ def title(self: LiteralString) -> LiteralString: ...
+ @overload
def title(self) -> str: ... # type: ignore[misc]
def translate(self, table: _TranslateTable, /) -> str: ...
+ @overload
+ def upper(self: LiteralString) -> LiteralString: ...
+ @overload
def upper(self) -> str: ... # type: ignore[misc]
+ @overload
+ def zfill(self: LiteralString, width: SupportsIndex, /) -> LiteralString: ...
+ @overload
def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc]
@staticmethod
@overload
@@ -505,21 +585,39 @@ class str(Sequence[str]):
@staticmethod
@overload
def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ...
+ @overload
+ def __add__(self: LiteralString, value: LiteralString, /) -> LiteralString: ...
+ @overload
def __add__(self, value: str, /) -> str: ... # type: ignore[misc]
# Incompatible with Sequence.__contains__
def __contains__(self, key: str, /) -> bool: ... # type: ignore[override]
def __eq__(self, value: object, /) -> bool: ...
def __ge__(self, value: str, /) -> bool: ...
- def __getitem__(self, key: SupportsIndex | slice, /) -> str: ...
+ @overload
+ def __getitem__(self: LiteralString, key: SupportsIndex | slice, /) -> LiteralString: ...
+ @overload
+ def __getitem__(self, key: SupportsIndex | slice, /) -> str: ... # type: ignore[misc]
def __gt__(self, value: str, /) -> bool: ...
def __hash__(self) -> int: ...
+ @overload
+ def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
+ @overload
def __iter__(self) -> Iterator[str]: ... # type: ignore[misc]
def __le__(self, value: str, /) -> bool: ...
def __len__(self) -> int: ...
def __lt__(self, value: str, /) -> bool: ...
+ @overload
+ def __mod__(self: LiteralString, value: LiteralString | tuple[LiteralString, ...], /) -> LiteralString: ...
+ @overload
def __mod__(self, value: Any, /) -> str: ...
+ @overload
+ def __mul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
+ @overload
def __mul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
def __ne__(self, value: object, /) -> bool: ...
+ @overload
+ def __rmul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
+ @overload
def __rmul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
def __getnewargs__(self) -> tuple[str]: ...
@@ -1673,7 +1771,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
# without creating many false-positive errors (see #7578).
# Instead, we special-case the most common examples of this: bool and literal integers.
@overload
-def sum(iterable: Iterable[bool], /, start: int = 0) -> int: ...
+def sum(iterable: Iterable[bool | _LiteralInteger], /, start: int = 0) -> int: ...
@overload
def sum(iterable: Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0]: ...
@overload
diff --git a/mypy/typeshed/stdlib/codeop.pyi b/mypy/typeshed/stdlib/codeop.pyi
index 6a51b7786384..cfe52e9b35de 100644
--- a/mypy/typeshed/stdlib/codeop.pyi
+++ b/mypy/typeshed/stdlib/codeop.pyi
@@ -1,3 +1,4 @@
+import sys
from types import CodeType
__all__ = ["compile_command", "Compile", "CommandCompiler"]
@@ -6,7 +7,10 @@ def compile_command(source: str, filename: str = "", symbol: str = "singl
class Compile:
flags: int
- def __call__(self, source: str, filename: str, symbol: str) -> CodeType: ...
+ if sys.version_info >= (3, 13):
+ def __call__(self, source: str, filename: str, symbol: str, flags: int = 0) -> CodeType: ...
+ else:
+ def __call__(self, source: str, filename: str, symbol: str) -> CodeType: ...
class CommandCompiler:
compiler: Compile
diff --git a/mypy/typeshed/stdlib/concurrent/futures/process.pyi b/mypy/typeshed/stdlib/concurrent/futures/process.pyi
index a1de3d679b23..97dc261be7ed 100644
--- a/mypy/typeshed/stdlib/concurrent/futures/process.pyi
+++ b/mypy/typeshed/stdlib/concurrent/futures/process.pyi
@@ -72,9 +72,19 @@ class _CallItem:
class _SafeQueue(Queue[Future[Any]]):
pending_work_items: dict[int, _WorkItem[Any]]
- shutdown_lock: Lock
+ if sys.version_info < (3, 12):
+ shutdown_lock: Lock
thread_wakeup: _ThreadWakeup
- if sys.version_info >= (3, 9):
+ if sys.version_info >= (3, 12):
+ def __init__(
+ self,
+ max_size: int | None = 0,
+ *,
+ ctx: BaseContext,
+ pending_work_items: dict[int, _WorkItem[Any]],
+ thread_wakeup: _ThreadWakeup,
+ ) -> None: ...
+ elif sys.version_info >= (3, 9):
def __init__(
self,
max_size: int | None = 0,
diff --git a/mypy/typeshed/stdlib/gzip.pyi b/mypy/typeshed/stdlib/gzip.pyi
index 9b32008dcbf6..b7fb40fbd82e 100644
--- a/mypy/typeshed/stdlib/gzip.pyi
+++ b/mypy/typeshed/stdlib/gzip.pyi
@@ -2,8 +2,8 @@ import _compression
import sys
import zlib
from _typeshed import ReadableBuffer, SizedBuffer, StrOrBytesPath
-from io import FileIO
-from typing import Final, Literal, Protocol, TextIO, overload
+from io import FileIO, TextIOWrapper
+from typing import Final, Literal, Protocol, overload
from typing_extensions import TypeAlias
__all__ = ["BadGzipFile", "GzipFile", "open", "compress", "decompress"]
@@ -57,13 +57,13 @@ def open(
) -> GzipFile: ...
@overload
def open(
- filename: StrOrBytesPath,
+ filename: StrOrBytesPath | _ReadableFileobj | _WritableFileobj,
mode: _OpenTextMode,
compresslevel: int = 9,
encoding: str | None = None,
errors: str | None = None,
newline: str | None = None,
-) -> TextIO: ...
+) -> TextIOWrapper: ...
@overload
def open(
filename: StrOrBytesPath | _ReadableFileobj | _WritableFileobj,
@@ -72,7 +72,7 @@ def open(
encoding: str | None = None,
errors: str | None = None,
newline: str | None = None,
-) -> GzipFile | TextIO: ...
+) -> GzipFile | TextIOWrapper: ...
class _PaddedFile:
file: _ReadableFileobj
diff --git a/mypy/typeshed/stdlib/multiprocessing/reduction.pyi b/mypy/typeshed/stdlib/multiprocessing/reduction.pyi
index 473e90936d71..942e92ce530e 100644
--- a/mypy/typeshed/stdlib/multiprocessing/reduction.pyi
+++ b/mypy/typeshed/stdlib/multiprocessing/reduction.pyi
@@ -1,12 +1,12 @@
import pickle
import sys
+from _pickle import _ReducedType
from _typeshed import HasFileno, SupportsWrite, Unused
from abc import ABCMeta
from builtins import type as Type # alias to avoid name clash
from collections.abc import Callable
from copyreg import _DispatchTableType
from multiprocessing import connection
-from pickle import _ReducedType
from socket import socket
from typing import Any, Final
diff --git a/mypy/typeshed/stdlib/pickle.pyi b/mypy/typeshed/stdlib/pickle.pyi
index 9bea92ef1c9e..5e398f2d4921 100644
--- a/mypy/typeshed/stdlib/pickle.pyi
+++ b/mypy/typeshed/stdlib/pickle.pyi
@@ -1,7 +1,20 @@
+from _pickle import (
+ PickleError as PickleError,
+ Pickler as Pickler,
+ PicklingError as PicklingError,
+ Unpickler as Unpickler,
+ UnpicklingError as UnpicklingError,
+ _BufferCallback,
+ _ReadableFileobj,
+ _ReducedType,
+ dump as dump,
+ dumps as dumps,
+ load as load,
+ loads as loads,
+)
from _typeshed import ReadableBuffer, SupportsWrite
-from collections.abc import Callable, Iterable, Iterator, Mapping
-from typing import Any, ClassVar, Protocol, SupportsBytes, SupportsIndex, final
-from typing_extensions import TypeAlias
+from collections.abc import Callable, Iterable, Mapping
+from typing import Any, ClassVar, SupportsBytes, SupportsIndex, final
__all__ = [
"PickleBuffer",
@@ -93,10 +106,6 @@ DEFAULT_PROTOCOL: int
bytes_types: tuple[type[Any], ...] # undocumented
-class _ReadableFileobj(Protocol):
- def read(self, n: int, /) -> bytes: ...
- def readline(self) -> bytes: ...
-
@final
class PickleBuffer:
def __init__(self, buffer: ReadableBuffer) -> None: ...
@@ -105,84 +114,6 @@ class PickleBuffer:
def __buffer__(self, flags: int, /) -> memoryview: ...
def __release_buffer__(self, buffer: memoryview, /) -> None: ...
-_BufferCallback: TypeAlias = Callable[[PickleBuffer], Any] | None
-
-def dump(
- obj: Any,
- file: SupportsWrite[bytes],
- protocol: int | None = None,
- *,
- fix_imports: bool = True,
- buffer_callback: _BufferCallback = None,
-) -> None: ...
-def dumps(
- obj: Any, protocol: int | None = None, *, fix_imports: bool = True, buffer_callback: _BufferCallback = None
-) -> bytes: ...
-def load(
- file: _ReadableFileobj,
- *,
- fix_imports: bool = True,
- encoding: str = "ASCII",
- errors: str = "strict",
- buffers: Iterable[Any] | None = (),
-) -> Any: ...
-def loads(
- data: ReadableBuffer,
- /,
- *,
- fix_imports: bool = True,
- encoding: str = "ASCII",
- errors: str = "strict",
- buffers: Iterable[Any] | None = (),
-) -> Any: ...
-
-class PickleError(Exception): ...
-class PicklingError(PickleError): ...
-class UnpicklingError(PickleError): ...
-
-_ReducedType: TypeAlias = (
- str
- | tuple[Callable[..., Any], tuple[Any, ...]]
- | tuple[Callable[..., Any], tuple[Any, ...], Any]
- | tuple[Callable[..., Any], tuple[Any, ...], Any, Iterator[Any] | None]
- | tuple[Callable[..., Any], tuple[Any, ...], Any, Iterator[Any] | None, Iterator[Any] | None]
-)
-
-class Pickler:
- fast: bool
- dispatch_table: Mapping[type, Callable[[Any], _ReducedType]]
- bin: bool # undocumented
- dispatch: ClassVar[dict[type, Callable[[Unpickler, Any], None]]] # undocumented, _Pickler only
-
- def __init__(
- self,
- file: SupportsWrite[bytes],
- protocol: int | None = None,
- *,
- fix_imports: bool = True,
- buffer_callback: _BufferCallback = None,
- ) -> None: ...
- def reducer_override(self, obj: Any) -> Any: ...
- def dump(self, obj: Any, /) -> None: ...
- def clear_memo(self) -> None: ...
- def persistent_id(self, obj: Any) -> Any: ...
-
-class Unpickler:
- dispatch: ClassVar[dict[int, Callable[[Unpickler], None]]] # undocumented, _Unpickler only
-
- def __init__(
- self,
- file: _ReadableFileobj,
- *,
- fix_imports: bool = True,
- encoding: str = "ASCII",
- errors: str = "strict",
- buffers: Iterable[Any] | None = (),
- ) -> None: ...
- def load(self) -> Any: ...
- def find_class(self, module_name: str, global_name: str, /) -> Any: ...
- def persistent_load(self, pid: Any) -> Any: ...
-
MARK: bytes
STOP: bytes
POP: bytes
@@ -266,6 +197,36 @@ READONLY_BUFFER: bytes
def encode_long(x: int) -> bytes: ... # undocumented
def decode_long(data: Iterable[SupportsIndex] | SupportsBytes | ReadableBuffer) -> int: ... # undocumented
-# pure-Python implementations
-_Pickler = Pickler # undocumented
-_Unpickler = Unpickler # undocumented
+# undocumented pure-Python implementations
+class _Pickler:
+ fast: bool
+ dispatch_table: Mapping[type, Callable[[Any], _ReducedType]]
+ bin: bool # undocumented
+ dispatch: ClassVar[dict[type, Callable[[Unpickler, Any], None]]] # undocumented, _Pickler only
+ reducer_override: Callable[[Any], Any]
+ def __init__(
+ self,
+ file: SupportsWrite[bytes],
+ protocol: int | None = None,
+ *,
+ fix_imports: bool = True,
+ buffer_callback: _BufferCallback = None,
+ ) -> None: ...
+ def dump(self, obj: Any) -> None: ...
+ def clear_memo(self) -> None: ...
+ def persistent_id(self, obj: Any) -> Any: ...
+
+class _Unpickler:
+ dispatch: ClassVar[dict[int, Callable[[Unpickler], None]]] # undocumented, _Unpickler only
+ def __init__(
+ self,
+ file: _ReadableFileobj,
+ *,
+ fix_imports: bool = True,
+ encoding: str = "ASCII",
+ errors: str = "strict",
+ buffers: Iterable[Any] | None = None,
+ ) -> None: ...
+ def load(self) -> Any: ...
+ def find_class(self, module: str, name: str) -> Any: ...
+ def persistent_load(self, pid: Any) -> Any: ...
diff --git a/mypy/typeshed/stdlib/pickletools.pyi b/mypy/typeshed/stdlib/pickletools.pyi
index 542172814926..cdade08d39a8 100644
--- a/mypy/typeshed/stdlib/pickletools.pyi
+++ b/mypy/typeshed/stdlib/pickletools.pyi
@@ -1,3 +1,4 @@
+import sys
from collections.abc import Callable, Iterator, MutableMapping
from typing import IO, Any
from typing_extensions import TypeAlias
@@ -40,7 +41,13 @@ def read_uint8(f: IO[bytes]) -> int: ...
uint8: ArgumentDescriptor
-def read_stringnl(f: IO[bytes], decode: bool = True, stripquotes: bool = True) -> bytes | str: ...
+if sys.version_info >= (3, 12):
+ def read_stringnl(
+ f: IO[bytes], decode: bool = True, stripquotes: bool = True, *, encoding: str = "latin-1"
+ ) -> bytes | str: ...
+
+else:
+ def read_stringnl(f: IO[bytes], decode: bool = True, stripquotes: bool = True) -> bytes | str: ...
stringnl: ArgumentDescriptor
diff --git a/mypy/typeshed/stdlib/select.pyi b/mypy/typeshed/stdlib/select.pyi
index 6d4c8d8f4c15..67203905ab66 100644
--- a/mypy/typeshed/stdlib/select.pyi
+++ b/mypy/typeshed/stdlib/select.pyi
@@ -10,7 +10,8 @@ if sys.platform != "win32":
POLLERR: int
POLLHUP: int
POLLIN: int
- POLLMSG: int
+ if sys.platform == "linux":
+ POLLMSG: int
POLLNVAL: int
POLLOUT: int
POLLPRI: int
@@ -77,7 +78,8 @@ if sys.platform != "linux" and sys.platform != "win32":
KQ_EV_ONESHOT: int
KQ_EV_SYSFLAGS: int
KQ_FILTER_AIO: int
- KQ_FILTER_NETDEV: int
+ if sys.platform != "darwin":
+ KQ_FILTER_NETDEV: int
KQ_FILTER_PROC: int
KQ_FILTER_READ: int
KQ_FILTER_SIGNAL: int
diff --git a/mypy/typeshed/stdlib/selectors.pyi b/mypy/typeshed/stdlib/selectors.pyi
index a857d0e242ab..7dad0c13bf2a 100644
--- a/mypy/typeshed/stdlib/selectors.pyi
+++ b/mypy/typeshed/stdlib/selectors.pyi
@@ -53,7 +53,7 @@ if sys.platform == "linux":
class DevpollSelector(_PollLikeSelector):
def fileno(self) -> int: ...
-if sys.platform != "win32":
+if sys.platform != "win32" and sys.platform != "linux":
class KqueueSelector(_BaseSelectorImpl):
def fileno(self) -> int: ...
def select(self, timeout: float | None = None) -> list[tuple[SelectorKey, _EventMask]]: ...
diff --git a/mypy/typeshed/stdlib/socket.pyi b/mypy/typeshed/stdlib/socket.pyi
index e42bba757fc3..ab22cced0bb5 100644
--- a/mypy/typeshed/stdlib/socket.pyi
+++ b/mypy/typeshed/stdlib/socket.pyi
@@ -367,7 +367,6 @@ if sys.platform != "win32" and sys.platform != "darwin":
IP_TRANSPARENT as IP_TRANSPARENT,
IPX_TYPE as IPX_TYPE,
SCM_CREDENTIALS as SCM_CREDENTIALS,
- SO_BINDTODEVICE as SO_BINDTODEVICE,
SO_DOMAIN as SO_DOMAIN,
SO_MARK as SO_MARK,
SO_PASSCRED as SO_PASSCRED,
@@ -396,7 +395,6 @@ if sys.platform != "win32" and sys.platform != "darwin":
__all__ += [
"IP_TRANSPARENT",
"SCM_CREDENTIALS",
- "SO_BINDTODEVICE",
"SO_DOMAIN",
"SO_MARK",
"SO_PASSCRED",
@@ -517,6 +515,11 @@ if sys.platform != "win32":
"IPV6_RTHDRDSTOPTS",
]
+ if sys.platform != "darwin" or sys.version_info >= (3, 13):
+ from _socket import SO_BINDTODEVICE as SO_BINDTODEVICE
+
+ __all__ += ["SO_BINDTODEVICE"]
+
if sys.platform != "darwin" and sys.platform != "linux":
if sys.platform != "win32" or sys.version_info >= (3, 9):
from _socket import BDADDR_ANY as BDADDR_ANY, BDADDR_LOCAL as BDADDR_LOCAL, BTPROTO_RFCOMM as BTPROTO_RFCOMM
@@ -1046,7 +1049,6 @@ class AddressFamily(IntEnum):
AF_INET = 2
AF_INET6 = 10
AF_APPLETALK = 5
- AF_DECnet = ...
AF_IPX = 4
AF_SNA = 22
AF_UNSPEC = 0
@@ -1096,7 +1098,7 @@ class AddressFamily(IntEnum):
AF_INET = AddressFamily.AF_INET
AF_INET6 = AddressFamily.AF_INET6
AF_APPLETALK = AddressFamily.AF_APPLETALK
-AF_DECnet = AddressFamily.AF_DECnet
+AF_DECnet: Literal[12]
AF_IPX = AddressFamily.AF_IPX
AF_SNA = AddressFamily.AF_SNA
AF_UNSPEC = AddressFamily.AF_UNSPEC
diff --git a/mypy/typeshed/stdlib/sys/__init__.pyi b/mypy/typeshed/stdlib/sys/__init__.pyi
index c4b1adca9bc6..fb1e24f3e864 100644
--- a/mypy/typeshed/stdlib/sys/__init__.pyi
+++ b/mypy/typeshed/stdlib/sys/__init__.pyi
@@ -73,7 +73,7 @@ if sys.version_info >= (3, 10):
__stdin__: Final[TextIOWrapper | None] # Contains the original value of stdin
__stdout__: Final[TextIOWrapper | None] # Contains the original value of stdout
__stderr__: Final[TextIOWrapper | None] # Contains the original value of stderr
-tracebacklimit: int
+tracebacklimit: int | None
version: str
api_version: int
warnoptions: Any
diff --git a/mypy/typeshed/stdlib/tarfile.pyi b/mypy/typeshed/stdlib/tarfile.pyi
index a7135d8150ee..a717c280a423 100644
--- a/mypy/typeshed/stdlib/tarfile.pyi
+++ b/mypy/typeshed/stdlib/tarfile.pyi
@@ -1,7 +1,7 @@
import bz2
import io
import sys
-from _typeshed import StrOrBytesPath, StrPath, SupportsRead
+from _typeshed import ReadableBuffer, StrOrBytesPath, StrPath, SupportsRead, WriteableBuffer
from builtins import list as _list # aliases to avoid name clashes with fields named "type" or "list"
from collections.abc import Callable, Iterable, Iterator, Mapping
from gzip import _ReadableFileobj as _GzipReadableFileobj, _WritableFileobj as _GzipWritableFileobj
@@ -226,15 +226,29 @@ def open(
errorlevel: int | None = ...,
preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None = ...,
) -> TarFile: ...
-
-# TODO: Temporary fallback for modes containing pipe characters. These don't
-# work with mypy 1.10, but this should be fixed with mypy 1.11.
-# https://github.com/python/typeshed/issues/12182
@overload
def open(
- name: StrOrBytesPath | None = None,
+ name: StrOrBytesPath | ReadableBuffer | None = None,
+ *,
+ mode: Literal["r|*", "r|", "r|gz", "r|bz2", "r|xz"],
+ fileobj: IO[bytes] | None = None,
+ bufsize: int = 10240,
+ format: int | None = ...,
+ tarinfo: type[TarInfo] | None = ...,
+ dereference: bool | None = ...,
+ ignore_zeros: bool | None = ...,
+ encoding: str | None = ...,
+ errors: str = ...,
+ pax_headers: Mapping[str, str] | None = ...,
+ debug: int | None = ...,
+ errorlevel: int | None = ...,
+ preset: int | None = ...,
+) -> TarFile: ...
+@overload
+def open(
+ name: StrOrBytesPath | WriteableBuffer | None = None,
*,
- mode: str,
+ mode: Literal["w|", "w|gz", "w|bz2", "w|xz"],
fileobj: IO[bytes] | None = None,
bufsize: int = 10240,
format: int | None = ...,
@@ -557,7 +571,7 @@ class TarInfo:
self,
*,
name: str = ...,
- mtime: int = ...,
+ mtime: float = ...,
mode: int = ...,
linkname: str = ...,
uid: int = ...,
diff --git a/mypy/typeshed/stdlib/tkinter/__init__.pyi b/mypy/typeshed/stdlib/tkinter/__init__.pyi
index d6a234d67919..a9ec97c45b40 100644
--- a/mypy/typeshed/stdlib/tkinter/__init__.pyi
+++ b/mypy/typeshed/stdlib/tkinter/__init__.pyi
@@ -403,6 +403,9 @@ class Misc:
# after_idle is essentially partialmethod(after, "idle")
def after_idle(self, func: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> str: ...
def after_cancel(self, id: str) -> None: ...
+ if sys.version_info >= (3, 13):
+ def after_info(self, id: str | None = None) -> tuple[str, ...]: ...
+
def bell(self, displayof: Literal[0] | Misc | None = 0) -> None: ...
def clipboard_get(self, *, displayof: Misc = ..., type: str = ...) -> str: ...
def clipboard_clear(self, *, displayof: Misc = ...) -> None: ...
@@ -659,6 +662,38 @@ class YView:
@overload
def yview_scroll(self, number: _ScreenUnits, what: Literal["pixels"]) -> None: ...
+if sys.platform == "darwin":
+ @type_check_only
+ class _WmAttributes(TypedDict):
+ alpha: float
+ fullscreen: bool
+ modified: bool
+ notify: bool
+ titlepath: str
+ topmost: bool
+ transparent: bool
+ type: str # Present, but not actually used on darwin
+
+elif sys.platform == "win32":
+ @type_check_only
+ class _WmAttributes(TypedDict):
+ alpha: float
+ transparentcolor: str
+ disabled: bool
+ fullscreen: bool
+ toolwindow: bool
+ topmost: bool
+
+else:
+ # X11
+ @type_check_only
+ class _WmAttributes(TypedDict):
+ alpha: float
+ topmost: bool
+ zoomed: bool
+ fullscreen: bool
+ type: str
+
class Wm:
@overload
def wm_aspect(self, minNumer: int, minDenom: int, maxNumer: int, maxDenom: int) -> None: ...
@@ -667,12 +702,144 @@ class Wm:
self, minNumer: None = None, minDenom: None = None, maxNumer: None = None, maxDenom: None = None
) -> tuple[int, int, int, int] | None: ...
aspect = wm_aspect
+ if sys.version_info >= (3, 13):
+ @overload
+ def wm_attributes(self, *, return_python_dict: Literal[False] = False) -> tuple[Any, ...]: ...
+ @overload
+ def wm_attributes(self, *, return_python_dict: Literal[True]) -> _WmAttributes: ...
+
+ else:
+ @overload
+ def wm_attributes(self) -> tuple[Any, ...]: ...
+
+ @overload
+ def wm_attributes(self, option: Literal["-alpha"], /) -> float: ...
@overload
- def wm_attributes(self) -> tuple[Any, ...]: ...
+ def wm_attributes(self, option: Literal["-fullscreen"], /) -> bool: ...
+ @overload
+ def wm_attributes(self, option: Literal["-topmost"], /) -> bool: ...
+ if sys.platform == "darwin":
+ @overload
+ def wm_attributes(self, option: Literal["-modified"], /) -> bool: ...
+ @overload
+ def wm_attributes(self, option: Literal["-notify"], /) -> bool: ...
+ @overload
+ def wm_attributes(self, option: Literal["-titlepath"], /) -> str: ...
+ @overload
+ def wm_attributes(self, option: Literal["-transparent"], /) -> bool: ...
+ @overload
+ def wm_attributes(self, option: Literal["-type"], /) -> str: ...
+ elif sys.platform == "win32":
+ @overload
+ def wm_attributes(self, option: Literal["-transparentcolor"], /) -> str: ...
+ @overload
+ def wm_attributes(self, option: Literal["-disabled"], /) -> bool: ...
+ @overload
+ def wm_attributes(self, option: Literal["-toolwindow"], /) -> bool: ...
+ else:
+ # X11
+ @overload
+ def wm_attributes(self, option: Literal["-zoomed"], /) -> bool: ...
+ @overload
+ def wm_attributes(self, option: Literal["-type"], /) -> str: ...
+ if sys.version_info >= (3, 13):
+ @overload
+ def wm_attributes(self, option: Literal["alpha"], /) -> float: ...
+ @overload
+ def wm_attributes(self, option: Literal["fullscreen"], /) -> bool: ...
+ @overload
+ def wm_attributes(self, option: Literal["topmost"], /) -> bool: ...
+ if sys.platform == "darwin":
+ @overload
+ def wm_attributes(self, option: Literal["modified"], /) -> bool: ...
+ @overload
+ def wm_attributes(self, option: Literal["notify"], /) -> bool: ...
+ @overload
+ def wm_attributes(self, option: Literal["titlepath"], /) -> str: ...
+ @overload
+ def wm_attributes(self, option: Literal["transparent"], /) -> bool: ...
+ @overload
+ def wm_attributes(self, option: Literal["type"], /) -> str: ...
+ elif sys.platform == "win32":
+ @overload
+ def wm_attributes(self, option: Literal["transparentcolor"], /) -> str: ...
+ @overload
+ def wm_attributes(self, option: Literal["disabled"], /) -> bool: ...
+ @overload
+ def wm_attributes(self, option: Literal["toolwindow"], /) -> bool: ...
+ else:
+ # X11
+ @overload
+ def wm_attributes(self, option: Literal["zoomed"], /) -> bool: ...
+ @overload
+ def wm_attributes(self, option: Literal["type"], /) -> str: ...
+
@overload
def wm_attributes(self, option: str, /): ...
@overload
- def wm_attributes(self, option: str, value, /, *__other_option_value_pairs: Any) -> None: ...
+ def wm_attributes(self, option: Literal["-alpha"], value: float, /) -> Literal[""]: ...
+ @overload
+ def wm_attributes(self, option: Literal["-fullscreen"], value: bool, /) -> Literal[""]: ...
+ @overload
+ def wm_attributes(self, option: Literal["-topmost"], value: bool, /) -> Literal[""]: ...
+ if sys.platform == "darwin":
+ @overload
+ def wm_attributes(self, option: Literal["-modified"], value: bool, /) -> Literal[""]: ...
+ @overload
+ def wm_attributes(self, option: Literal["-notify"], value: bool, /) -> Literal[""]: ...
+ @overload
+ def wm_attributes(self, option: Literal["-titlepath"], value: str, /) -> Literal[""]: ...
+ @overload
+ def wm_attributes(self, option: Literal["-transparent"], value: bool, /) -> Literal[""]: ...
+ elif sys.platform == "win32":
+ @overload
+ def wm_attributes(self, option: Literal["-transparentcolor"], value: str, /) -> Literal[""]: ...
+ @overload
+ def wm_attributes(self, option: Literal["-disabled"], value: bool, /) -> Literal[""]: ...
+ @overload
+ def wm_attributes(self, option: Literal["-toolwindow"], value: bool, /) -> Literal[""]: ...
+ else:
+ # X11
+ @overload
+ def wm_attributes(self, option: Literal["-zoomed"], value: bool, /) -> Literal[""]: ...
+ @overload
+ def wm_attributes(self, option: Literal["-type"], value: str, /) -> Literal[""]: ...
+
+ @overload
+ def wm_attributes(self, option: str, value, /, *__other_option_value_pairs: Any) -> Literal[""]: ...
+ if sys.version_info >= (3, 13):
+ if sys.platform == "darwin":
+ @overload
+ def wm_attributes(
+ self,
+ *,
+ alpha: float = ...,
+ fullscreen: bool = ...,
+ modified: bool = ...,
+ notify: bool = ...,
+ titlepath: str = ...,
+ topmost: bool = ...,
+ transparent: bool = ...,
+ ) -> None: ...
+ elif sys.platform == "win32":
+ @overload
+ def wm_attributes(
+ self,
+ *,
+ alpha: float = ...,
+ transparentcolor: str = ...,
+ disabled: bool = ...,
+ fullscreen: bool = ...,
+ toolwindow: bool = ...,
+ topmost: bool = ...,
+ ) -> None: ...
+ else:
+ # X11
+ @overload
+ def wm_attributes(
+ self, *, alpha: float = ..., topmost: bool = ..., zoomed: bool = ..., fullscreen: bool = ..., type: str = ...
+ ) -> None: ...
+
attributes = wm_attributes
def wm_client(self, name: str | None = None) -> str: ...
client = wm_client
diff --git a/mypy/typeshed/stdlib/token.pyi b/mypy/typeshed/stdlib/token.pyi
index 668987d7c2bf..741ce5b035b7 100644
--- a/mypy/typeshed/stdlib/token.pyi
+++ b/mypy/typeshed/stdlib/token.pyi
@@ -76,7 +76,7 @@ if sys.version_info >= (3, 10):
__all__ += ["SOFT_KEYWORD"]
if sys.version_info >= (3, 12):
- __all__ += ["EXCLAMATION", "FSTRING_END", "FSTRING_MIDDLE", "FSTRING_START"]
+ __all__ += ["EXCLAMATION", "FSTRING_END", "FSTRING_MIDDLE", "FSTRING_START", "EXACT_TOKEN_TYPES"]
ENDMARKER: int
NAME: int
diff --git a/mypy/typeshed/stdlib/tokenize.pyi b/mypy/typeshed/stdlib/tokenize.pyi
index 7e9a945cdc46..7b68f791a8c0 100644
--- a/mypy/typeshed/stdlib/tokenize.pyi
+++ b/mypy/typeshed/stdlib/tokenize.pyi
@@ -88,7 +88,7 @@ if sys.version_info >= (3, 10):
__all__ += ["SOFT_KEYWORD"]
if sys.version_info >= (3, 12):
- __all__ += ["EXCLAMATION", "FSTRING_END", "FSTRING_MIDDLE", "FSTRING_START"]
+ __all__ += ["EXCLAMATION", "FSTRING_END", "FSTRING_MIDDLE", "FSTRING_START", "EXACT_TOKEN_TYPES"]
if sys.version_info >= (3, 13):
__all__ += ["TokenError", "open"]
diff --git a/mypy/typeshed/stdlib/typing.pyi b/mypy/typeshed/stdlib/typing.pyi
index 8f0d4fbb6a02..741e7b8a3167 100644
--- a/mypy/typeshed/stdlib/typing.pyi
+++ b/mypy/typeshed/stdlib/typing.pyi
@@ -757,7 +757,7 @@ class MutableMapping(Mapping[_KT, _VT]):
Text = str
-TYPE_CHECKING: bool
+TYPE_CHECKING: Final[bool]
# In stubs, the arguments of the IO class are marked as positional-only.
# This differs from runtime, but better reflects the fact that in reality
diff --git a/mypy/typeshed/stdlib/weakref.pyi b/mypy/typeshed/stdlib/weakref.pyi
index 853caf3e8abb..4203756c718d 100644
--- a/mypy/typeshed/stdlib/weakref.pyi
+++ b/mypy/typeshed/stdlib/weakref.pyi
@@ -172,11 +172,11 @@ class WeakKeyDictionary(MutableMapping[_KT, _VT]):
@overload
def __ior__(self, other: Iterable[tuple[_KT, _VT]]) -> Self: ...
-class finalize: # TODO: This is a good candidate for to be a `Generic[_P, _T]` class
- def __init__(self, obj: object, func: Callable[_P, Any], /, *args: _P.args, **kwargs: _P.kwargs) -> None: ...
+class finalize(Generic[_P, _T]):
+ def __init__(self, obj: _T, func: Callable[_P, Any], /, *args: _P.args, **kwargs: _P.kwargs) -> None: ...
def __call__(self, _: Any = None) -> Any | None: ...
- def detach(self) -> tuple[Any, Any, tuple[Any, ...], dict[str, Any]] | None: ...
- def peek(self) -> tuple[Any, Any, tuple[Any, ...], dict[str, Any]] | None: ...
+ def detach(self) -> tuple[_T, Callable[_P, Any], tuple[Any, ...], dict[str, Any]] | None: ...
+ def peek(self) -> tuple[_T, Callable[_P, Any], tuple[Any, ...], dict[str, Any]] | None: ...
@property
def alive(self) -> bool: ...
atexit: bool
diff --git a/mypy/typeshed/stdlib/xml/sax/expatreader.pyi b/mypy/typeshed/stdlib/xml/sax/expatreader.pyi
new file mode 100644
index 000000000000..0f7bda5872c0
--- /dev/null
+++ b/mypy/typeshed/stdlib/xml/sax/expatreader.pyi
@@ -0,0 +1,53 @@
+import sys
+from _typeshed import Unused
+from xml.sax import xmlreader
+
+version: str
+AttributesImpl = xmlreader.AttributesImpl
+AttributesNSImpl = xmlreader.AttributesNSImpl
+
+class _ClosedParser: ...
+
+class ExpatLocator(xmlreader.Locator):
+ def __init__(self, parser: ExpatParser) -> None: ...
+ def getColumnNumber(self) -> int: ...
+ def getLineNumber(self) -> int: ...
+ def getPublicId(self): ...
+ def getSystemId(self): ...
+
+class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator):
+ def __init__(self, namespaceHandling: int = 0, bufsize: int = 65516) -> None: ...
+ def parse(self, source) -> None: ...
+ def prepareParser(self, source) -> None: ...
+ def setContentHandler(self, handler) -> None: ...
+ def getFeature(self, name: str): ...
+ def setFeature(self, name: str, state) -> None: ...
+ def getProperty(self, name: str): ...
+ def setProperty(self, name: str, value) -> None: ...
+ if sys.version_info >= (3, 9):
+ def feed(self, data, isFinal: bool = False) -> None: ...
+ else:
+ def feed(self, data, isFinal: int = 0) -> None: ...
+
+ def flush(self) -> None: ...
+ def close(self) -> None: ...
+ def reset(self) -> None: ...
+ def getColumnNumber(self) -> int | None: ...
+ def getLineNumber(self) -> int: ...
+ def getPublicId(self): ...
+ def getSystemId(self): ...
+ def start_element(self, name: str, attrs: xmlreader.AttributesImpl) -> None: ...
+ def end_element(self, name: str) -> None: ...
+ def start_element_ns(self, name: str, attrs) -> None: ...
+ def end_element_ns(self, name: str) -> None: ...
+ def processing_instruction(self, target: str, data: str) -> None: ...
+ def character_data(self, data: str) -> None: ...
+ def start_namespace_decl(self, prefix: str | None, uri: str) -> None: ...
+ def end_namespace_decl(self, prefix: str | None) -> None: ...
+ def start_doctype_decl(self, name: str, sysid: str | None, pubid: str | None, has_internal_subset: Unused) -> None: ...
+ def unparsed_entity_decl(self, name, base, sysid, pubid, notation_name) -> None: ...
+ def notation_decl(self, name, base, sysid, pubid) -> None: ...
+ def external_entity_ref(self, context, base, sysid, pubid): ...
+ def skipped_entity_handler(self, name: str, is_pe: bool) -> None: ...
+
+def create_parser(namespaceHandling: int = 0, bufsize: int = 65516) -> ExpatParser: ...
diff --git a/mypy/typeshed/stdlib/zipfile/_path.pyi b/mypy/typeshed/stdlib/zipfile/_path/__init__.pyi
similarity index 100%
rename from mypy/typeshed/stdlib/zipfile/_path.pyi
rename to mypy/typeshed/stdlib/zipfile/_path/__init__.pyi
diff --git a/mypy/typeshed/stdlib/zipfile/_path/glob.pyi b/mypy/typeshed/stdlib/zipfile/_path/glob.pyi
new file mode 100644
index 000000000000..f25ae71725c0
--- /dev/null
+++ b/mypy/typeshed/stdlib/zipfile/_path/glob.pyi
@@ -0,0 +1,22 @@
+import sys
+from collections.abc import Iterator
+from re import Match
+
+if sys.version_info >= (3, 13):
+ class Translator:
+ def __init__(self, seps: str = ...) -> None: ...
+ def translate(self, pattern: str) -> str: ...
+ def extend(self, pattern: str) -> str: ...
+ def match_dirs(self, pattern: str) -> str: ...
+ def translate_core(self, pattern: str) -> str: ...
+ def replace(self, match: Match[str]) -> str: ...
+ def restrict_rglob(self, pattern: str) -> None: ...
+ def star_not_empty(self, pattern: str) -> str: ...
+
+else:
+ def translate(pattern: str) -> str: ...
+ def match_dirs(pattern: str) -> str: ...
+ def translate_core(pattern: str) -> str: ...
+ def replace(match: Match[str]) -> str: ...
+
+def separate(pattern: str) -> Iterator[Match[str]]: ...
From 7fa10057336c58061c27cc90e042aa1eb3dddd3c Mon Sep 17 00:00:00 2001
From: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Date: Mon, 26 Sep 2022 12:55:07 -0700
Subject: [PATCH 2/4] Remove use of LiteralString in builtins (#13743)
---
mypy/typeshed/stdlib/builtins.pyi | 100 +-----------------------------
1 file changed, 1 insertion(+), 99 deletions(-)
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
index 4c7467fc84c8..773a7e1573fc 100644
--- a/mypy/typeshed/stdlib/builtins.pyi
+++ b/mypy/typeshed/stdlib/builtins.pyi
@@ -64,7 +64,6 @@ from typing import ( # noqa: Y022
from typing_extensions import ( # noqa: Y023
Concatenate,
Literal,
- LiteralString,
ParamSpec,
Self,
TypeAlias,
@@ -442,31 +441,16 @@ class str(Sequence[str]):
def __new__(cls, object: object = ...) -> Self: ...
@overload
def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
- @overload
- def capitalize(self: LiteralString) -> LiteralString: ...
- @overload
def capitalize(self) -> str: ... # type: ignore[misc]
- @overload
- def casefold(self: LiteralString) -> LiteralString: ...
- @overload
def casefold(self) -> str: ... # type: ignore[misc]
- @overload
- def center(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
- @overload
def center(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
def count(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
def endswith(
self, suffix: str | tuple[str, ...], start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
) -> bool: ...
- @overload
- def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
- @overload
def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
def find(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
- @overload
- def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
- @overload
def format(self, *args: object, **kwargs: object) -> str: ...
def format_map(self, mapping: _FormatMapMapping, /) -> str: ...
def index(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
@@ -482,99 +466,35 @@ class str(Sequence[str]):
def isspace(self) -> bool: ...
def istitle(self) -> bool: ...
def isupper(self) -> bool: ...
- @overload
- def join(self: LiteralString, iterable: Iterable[LiteralString], /) -> LiteralString: ...
- @overload
def join(self, iterable: Iterable[str], /) -> str: ... # type: ignore[misc]
- @overload
- def ljust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
- @overload
def ljust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
- @overload
- def lower(self: LiteralString) -> LiteralString: ...
- @overload
def lower(self) -> str: ... # type: ignore[misc]
- @overload
- def lstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
- @overload
def lstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
- @overload
- def partition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
- @overload
def partition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
if sys.version_info >= (3, 13):
- @overload
- def replace(
- self: LiteralString, old: LiteralString, new: LiteralString, /, count: SupportsIndex = -1
- ) -> LiteralString: ...
- @overload
def replace(self, old: str, new: str, /, count: SupportsIndex = -1) -> str: ... # type: ignore[misc]
else:
- @overload
- def replace(
- self: LiteralString, old: LiteralString, new: LiteralString, count: SupportsIndex = -1, /
- ) -> LiteralString: ...
- @overload
def replace(self, old: str, new: str, count: SupportsIndex = -1, /) -> str: ... # type: ignore[misc]
if sys.version_info >= (3, 9):
- @overload
- def removeprefix(self: LiteralString, prefix: LiteralString, /) -> LiteralString: ...
- @overload
def removeprefix(self, prefix: str, /) -> str: ... # type: ignore[misc]
- @overload
- def removesuffix(self: LiteralString, suffix: LiteralString, /) -> LiteralString: ...
- @overload
def removesuffix(self, suffix: str, /) -> str: ... # type: ignore[misc]
def rfind(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
def rindex(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
- @overload
- def rjust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
- @overload
def rjust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
- @overload
- def rpartition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
- @overload
def rpartition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
- @overload
- def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
- @overload
def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
- @overload
- def rstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
- @overload
def rstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
- @overload
- def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
- @overload
def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
- @overload
- def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ...
- @overload
def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
def startswith(
self, prefix: str | tuple[str, ...], start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
) -> bool: ...
- @overload
- def strip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
- @overload
def strip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
- @overload
- def swapcase(self: LiteralString) -> LiteralString: ...
- @overload
def swapcase(self) -> str: ... # type: ignore[misc]
- @overload
- def title(self: LiteralString) -> LiteralString: ...
- @overload
def title(self) -> str: ... # type: ignore[misc]
def translate(self, table: _TranslateTable, /) -> str: ...
- @overload
- def upper(self: LiteralString) -> LiteralString: ...
- @overload
def upper(self) -> str: ... # type: ignore[misc]
- @overload
- def zfill(self: LiteralString, width: SupportsIndex, /) -> LiteralString: ...
- @overload
def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc]
@staticmethod
@overload
@@ -585,39 +505,21 @@ class str(Sequence[str]):
@staticmethod
@overload
def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ...
- @overload
- def __add__(self: LiteralString, value: LiteralString, /) -> LiteralString: ...
- @overload
def __add__(self, value: str, /) -> str: ... # type: ignore[misc]
# Incompatible with Sequence.__contains__
def __contains__(self, key: str, /) -> bool: ... # type: ignore[override]
def __eq__(self, value: object, /) -> bool: ...
def __ge__(self, value: str, /) -> bool: ...
- @overload
- def __getitem__(self: LiteralString, key: SupportsIndex | slice, /) -> LiteralString: ...
- @overload
- def __getitem__(self, key: SupportsIndex | slice, /) -> str: ... # type: ignore[misc]
+ def __getitem__(self, key: SupportsIndex | slice, /) -> str: ...
def __gt__(self, value: str, /) -> bool: ...
def __hash__(self) -> int: ...
- @overload
- def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
- @overload
def __iter__(self) -> Iterator[str]: ... # type: ignore[misc]
def __le__(self, value: str, /) -> bool: ...
def __len__(self) -> int: ...
def __lt__(self, value: str, /) -> bool: ...
- @overload
- def __mod__(self: LiteralString, value: LiteralString | tuple[LiteralString, ...], /) -> LiteralString: ...
- @overload
def __mod__(self, value: Any, /) -> str: ...
- @overload
- def __mul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
- @overload
def __mul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
def __ne__(self, value: object, /) -> bool: ...
- @overload
- def __rmul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
- @overload
def __rmul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
def __getnewargs__(self) -> tuple[str]: ...
From ed0f5c4e6eea6136bb7a21809a8e18b39f43c742 Mon Sep 17 00:00:00 2001
From: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Date: Sat, 29 Oct 2022 12:47:21 -0700
Subject: [PATCH 3/4] Revert sum literal integer change (#13961)
This is allegedly causing large performance problems, see 13821
typeshed/8231 had zero hits on mypy_primer, so it's not the worst thing
to undo. Patching this in typeshed also feels weird, since there's a
more general soundness issue. If a typevar has a bound or constraint, we
might not want to solve it to a Literal.
If we can confirm the performance regression or fix the unsoundness
within mypy, I might pursue upstreaming this in typeshed.
(Reminder: add this to the sync_typeshed script once merged)
---
mypy/typeshed/stdlib/builtins.pyi | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi
index 773a7e1573fc..1a4ca925168a 100644
--- a/mypy/typeshed/stdlib/builtins.pyi
+++ b/mypy/typeshed/stdlib/builtins.pyi
@@ -1673,7 +1673,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
# without creating many false-positive errors (see #7578).
# Instead, we special-case the most common examples of this: bool and literal integers.
@overload
-def sum(iterable: Iterable[bool | _LiteralInteger], /, start: int = 0) -> int: ...
+def sum(iterable: Iterable[bool], /, start: int = 0) -> int: ...
@overload
def sum(iterable: Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0]: ...
@overload
From 5fc47221ce50d1dd25acb8574dfa41c165764d2c Mon Sep 17 00:00:00 2001
From: AlexWaygood
Date: Mon, 1 May 2023 20:34:55 +0100
Subject: [PATCH 4/4] Revert typeshed ctypes change Since the plugin provides
superior type checking:
https://github.com/python/mypy/pull/13987#issuecomment-1310863427 A manual
cherry-pick of e437cdf.
---
mypy/typeshed/stdlib/_ctypes.pyi | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/mypy/typeshed/stdlib/_ctypes.pyi b/mypy/typeshed/stdlib/_ctypes.pyi
index 1f3f8f38802b..ecb07a29bb75 100644
--- a/mypy/typeshed/stdlib/_ctypes.pyi
+++ b/mypy/typeshed/stdlib/_ctypes.pyi
@@ -286,11 +286,7 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType):
def _type_(self) -> type[_CT]: ...
@_type_.setter
def _type_(self, value: type[_CT]) -> None: ...
- # Note: only available if _CT == c_char
- @property
- def raw(self) -> bytes: ...
- @raw.setter
- def raw(self, value: ReadableBuffer) -> None: ...
+ raw: bytes # Note: only available if _CT == c_char
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
# TODO These methods cannot be annotated correctly at the moment.
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT