diff --git a/mypy/typeshed/stdlib/_codecs.pyi b/mypy/typeshed/stdlib/_codecs.pyi index 44cc0f78028c..51f17f01ca71 100644 --- a/mypy/typeshed/stdlib/_codecs.pyi +++ b/mypy/typeshed/stdlib/_codecs.pyi @@ -104,35 +104,35 @@ if sys.version_info < (3, 8): def unicode_internal_decode(__obj: str | ReadableBuffer, __errors: str | None = None) -> tuple[str, int]: ... def unicode_internal_encode(__obj: str | ReadableBuffer, __errors: str | None = None) -> tuple[bytes, int]: ... -def utf_16_be_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ... +def utf_16_be_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ... def utf_16_be_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ... -def utf_16_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ... +def utf_16_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ... def utf_16_encode(__str: str, __errors: str | None = None, __byteorder: int = 0) -> tuple[bytes, int]: ... def utf_16_ex_decode( - __data: ReadableBuffer, __errors: str | None = None, __byteorder: int = 0, __final: int = False + __data: ReadableBuffer, __errors: str | None = None, __byteorder: int = 0, __final: bool = False ) -> tuple[str, int, int]: ... -def utf_16_le_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ... +def utf_16_le_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ... def utf_16_le_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ... -def utf_32_be_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ... +def utf_32_be_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ... def utf_32_be_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ... -def utf_32_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ... +def utf_32_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ... def utf_32_encode(__str: str, __errors: str | None = None, __byteorder: int = 0) -> tuple[bytes, int]: ... def utf_32_ex_decode( - __data: ReadableBuffer, __errors: str | None = None, __byteorder: int = 0, __final: int = False + __data: ReadableBuffer, __errors: str | None = None, __byteorder: int = 0, __final: bool = False ) -> tuple[str, int, int]: ... -def utf_32_le_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ... +def utf_32_le_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ... def utf_32_le_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ... -def utf_7_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ... +def utf_7_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ... def utf_7_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ... -def utf_8_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ... +def utf_8_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ... def utf_8_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ... if sys.platform == "win32": - def mbcs_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ... + def mbcs_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ... def mbcs_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ... def code_page_decode( - __codepage: int, __data: ReadableBuffer, __errors: str | None = None, __final: int = False + __codepage: int, __data: ReadableBuffer, __errors: str | None = None, __final: bool = False ) -> tuple[str, int]: ... def code_page_encode(__code_page: int, __str: str, __errors: str | None = None) -> tuple[bytes, int]: ... - def oem_decode(__data: ReadableBuffer, __errors: str | None = None, __final: int = False) -> tuple[str, int]: ... + def oem_decode(__data: ReadableBuffer, __errors: str | None = None, __final: bool = False) -> tuple[str, int]: ... def oem_encode(__str: str, __errors: str | None = None) -> tuple[bytes, int]: ... diff --git a/mypy/typeshed/stdlib/_csv.pyi b/mypy/typeshed/stdlib/_csv.pyi index 7d15365d3b02..7e9b9e4e7a79 100644 --- a/mypy/typeshed/stdlib/_csv.pyi +++ b/mypy/typeshed/stdlib/_csv.pyi @@ -1,9 +1,9 @@ from _typeshed import SupportsWrite from collections.abc import Iterable, Iterator -from typing import Any, Union -from typing_extensions import Literal, TypeAlias +from typing import Any +from typing_extensions import Final, Literal, TypeAlias -__version__: str +__version__: Final[str] QUOTE_ALL: Literal[1] QUOTE_MINIMAL: Literal[0] @@ -27,7 +27,7 @@ class Dialect: strict: bool def __init__(self) -> None: ... -_DialectLike: TypeAlias = Union[str, Dialect, type[Dialect]] +_DialectLike: TypeAlias = str | Dialect | type[Dialect] class _reader(Iterator[list[str]]): @property diff --git a/mypy/typeshed/stdlib/_decimal.pyi b/mypy/typeshed/stdlib/_decimal.pyi index 38b8ac30cc2f..b8208fe180a1 100644 --- a/mypy/typeshed/stdlib/_decimal.pyi +++ b/mypy/typeshed/stdlib/_decimal.pyi @@ -1,17 +1,16 @@ import numbers import sys -from _typeshed import Self from collections.abc import Container, Sequence from types import TracebackType -from typing import Any, ClassVar, NamedTuple, Union, overload -from typing_extensions import Literal, TypeAlias +from typing import Any, ClassVar, NamedTuple, overload +from typing_extensions import Final, Literal, Self, TypeAlias _Decimal: TypeAlias = Decimal | int -_DecimalNew: TypeAlias = Union[Decimal, float, str, tuple[int, Sequence[int], int]] +_DecimalNew: TypeAlias = Decimal | float | str | tuple[int, Sequence[int], int] _ComparableNum: TypeAlias = Decimal | float | numbers.Rational -__version__: str -__libmpdec_version__: str +__version__: Final[str] +__libmpdec_version__: Final[str] class DecimalTuple(NamedTuple): sign: int @@ -69,9 +68,9 @@ else: def localcontext(ctx: Context | None = None) -> _ContextManager: ... class Decimal: - def __new__(cls: type[Self], value: _DecimalNew = ..., context: Context | None = ...) -> Self: ... + def __new__(cls, value: _DecimalNew = ..., context: Context | None = ...) -> Self: ... @classmethod - def from_float(cls: type[Self], __f: float) -> Self: ... + def from_float(cls, __f: float) -> Self: ... def __bool__(self) -> bool: ... def compare(self, other: _Decimal, context: Context | None = None) -> Decimal: ... def as_tuple(self) -> DecimalTuple: ... @@ -163,9 +162,9 @@ class Decimal: def rotate(self, other: _Decimal, context: Context | None = None) -> Decimal: ... def scaleb(self, other: _Decimal, context: Context | None = None) -> Decimal: ... def shift(self, other: _Decimal, context: Context | None = None) -> Decimal: ... - def __reduce__(self: Self) -> tuple[type[Self], tuple[str]]: ... - def __copy__(self: Self) -> Self: ... - def __deepcopy__(self: Self, __memo: Any) -> Self: ... + def __reduce__(self) -> tuple[type[Self], tuple[str]]: ... + def __copy__(self) -> Self: ... + def __deepcopy__(self, __memo: Any) -> Self: ... def __format__(self, __specifier: str, __context: Context | None = ...) -> str: ... class _ContextManager: @@ -203,7 +202,7 @@ class Context: traps: None | dict[_TrapType, bool] | Container[_TrapType] = ..., _ignored_flags: list[_TrapType] | None = ..., ) -> None: ... - def __reduce__(self: Self) -> tuple[type[Self], tuple[Any, ...]]: ... + def __reduce__(self) -> tuple[type[Self], tuple[Any, ...]]: ... def clear_flags(self) -> None: ... def clear_traps(self) -> None: ... def copy(self) -> Context: ... diff --git a/mypy/typeshed/stdlib/_heapq.pyi b/mypy/typeshed/stdlib/_heapq.pyi index 90dc28deb71f..8d6c3e88103e 100644 --- a/mypy/typeshed/stdlib/_heapq.pyi +++ b/mypy/typeshed/stdlib/_heapq.pyi @@ -1,8 +1,9 @@ from typing import Any, TypeVar +from typing_extensions import Final _T = TypeVar("_T") -__about__: str +__about__: Final[str] def heapify(__heap: list[Any]) -> None: ... def heappop(__heap: list[_T]) -> _T: ... diff --git a/mypy/typeshed/stdlib/_py_abc.pyi b/mypy/typeshed/stdlib/_py_abc.pyi index ddf04364a238..cc45c6ad3814 100644 --- a/mypy/typeshed/stdlib/_py_abc.pyi +++ b/mypy/typeshed/stdlib/_py_abc.pyi @@ -1,4 +1,4 @@ -from _typeshed import Self +import _typeshed from typing import Any, NewType, TypeVar _T = TypeVar("_T") @@ -8,5 +8,7 @@ _CacheToken = NewType("_CacheToken", int) def get_cache_token() -> _CacheToken: ... class ABCMeta(type): - def __new__(__mcls: type[Self], __name: str, __bases: tuple[type[Any], ...], __namespace: dict[str, Any]) -> Self: ... + def __new__( + __mcls: type[_typeshed.Self], __name: str, __bases: tuple[type[Any], ...], __namespace: dict[str, Any] + ) -> _typeshed.Self: ... def register(cls, subclass: type[_T]) -> type[_T]: ... diff --git a/mypy/typeshed/stdlib/_typeshed/__init__.pyi b/mypy/typeshed/stdlib/_typeshed/__init__.pyi index 68ac2a9b1900..d0c6b3ab1173 100644 --- a/mypy/typeshed/stdlib/_typeshed/__init__.pyi +++ b/mypy/typeshed/stdlib/_typeshed/__init__.pyi @@ -8,9 +8,10 @@ import mmap import pickle import sys from collections.abc import Awaitable, Callable, Iterable, Set as AbstractSet +from dataclasses import Field from os import PathLike from types import FrameType, TracebackType -from typing import Any, AnyStr, Generic, Protocol, TypeVar, Union +from typing import Any, AnyStr, ClassVar, Generic, Protocol, TypeVar from typing_extensions import Final, Literal, LiteralString, TypeAlias, final _KT = TypeVar("_KT") @@ -264,7 +265,7 @@ IndexableBuffer: TypeAlias = bytes | bytearray | memoryview | array.array[Any] | # def __buffer__(self, __flags: int) -> memoryview: ... ExcInfo: TypeAlias = tuple[type[BaseException], BaseException, TracebackType] -OptExcInfo: TypeAlias = Union[ExcInfo, tuple[None, None, None]] +OptExcInfo: TypeAlias = ExcInfo | tuple[None, None, None] # stable if sys.version_info >= (3, 10): @@ -304,3 +305,10 @@ ProfileFunction: TypeAlias = Callable[[FrameType, str, Any], object] # Objects suitable to be passed to sys.settrace, threading.settrace, and similar TraceFunction: TypeAlias = Callable[[FrameType, str, Any], TraceFunction | None] + +# experimental +# Might not work as expected for pyright, see +# https://github.com/python/typeshed/pull/9362 +# https://github.com/microsoft/pyright/issues/4339 +class DataclassInstance(Protocol): + __dataclass_fields__: ClassVar[dict[str, Field[Any]]] diff --git a/mypy/typeshed/stdlib/_weakref.pyi b/mypy/typeshed/stdlib/_weakref.pyi index df462ad859c7..2a43de3ffd6b 100644 --- a/mypy/typeshed/stdlib/_weakref.pyi +++ b/mypy/typeshed/stdlib/_weakref.pyi @@ -1,8 +1,7 @@ import sys -from _typeshed import Self from collections.abc import Callable from typing import Any, Generic, TypeVar, overload -from typing_extensions import final +from typing_extensions import Self, final if sys.version_info >= (3, 9): from types import GenericAlias @@ -21,7 +20,7 @@ class ProxyType(Generic[_T]): # "weakproxy" class ReferenceType(Generic[_T]): __callback__: Callable[[ReferenceType[_T]], Any] - def __new__(cls: type[Self], o: _T, callback: Callable[[ReferenceType[_T]], Any] | None = ...) -> Self: ... + def __new__(cls, o: _T, callback: Callable[[ReferenceType[_T]], Any] | None = ...) -> Self: ... def __call__(self) -> _T | None: ... if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any) -> GenericAlias: ... diff --git a/mypy/typeshed/stdlib/_weakrefset.pyi b/mypy/typeshed/stdlib/_weakrefset.pyi index fdf26641bbeb..d73d79155329 100644 --- a/mypy/typeshed/stdlib/_weakrefset.pyi +++ b/mypy/typeshed/stdlib/_weakrefset.pyi @@ -1,7 +1,7 @@ import sys -from _typeshed import Self from collections.abc import Iterable, Iterator, MutableSet from typing import Any, Generic, TypeVar, overload +from typing_extensions import Self if sys.version_info >= (3, 9): from types import GenericAlias @@ -18,21 +18,21 @@ class WeakSet(MutableSet[_T], Generic[_T]): def __init__(self, data: Iterable[_T]) -> None: ... def add(self, item: _T) -> None: ... def discard(self, item: _T) -> None: ... - def copy(self: Self) -> Self: ... + def copy(self) -> Self: ... def remove(self, item: _T) -> None: ... def update(self, other: Iterable[_T]) -> None: ... def __contains__(self, item: object) -> bool: ... def __len__(self) -> int: ... def __iter__(self) -> Iterator[_T]: ... - def __ior__(self: Self, other: Iterable[_T]) -> Self: ... # type: ignore[override,misc] - def difference(self: Self, other: Iterable[_T]) -> Self: ... - def __sub__(self: Self, other: Iterable[Any]) -> Self: ... + def __ior__(self, other: Iterable[_T]) -> Self: ... # type: ignore[override,misc] + def difference(self, other: Iterable[_T]) -> Self: ... + def __sub__(self, other: Iterable[Any]) -> Self: ... def difference_update(self, other: Iterable[Any]) -> None: ... - def __isub__(self: Self, other: Iterable[Any]) -> Self: ... - def intersection(self: Self, other: Iterable[_T]) -> Self: ... - def __and__(self: Self, other: Iterable[Any]) -> Self: ... + def __isub__(self, other: Iterable[Any]) -> Self: ... + def intersection(self, other: Iterable[_T]) -> Self: ... + def __and__(self, other: Iterable[Any]) -> Self: ... def intersection_update(self, other: Iterable[Any]) -> None: ... - def __iand__(self: Self, other: Iterable[Any]) -> Self: ... + def __iand__(self, other: Iterable[Any]) -> Self: ... def issubset(self, other: Iterable[_T]) -> bool: ... def __le__(self, other: Iterable[_T]) -> bool: ... def __lt__(self, other: Iterable[_T]) -> bool: ... @@ -43,7 +43,7 @@ class WeakSet(MutableSet[_T], Generic[_T]): def symmetric_difference(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ... def __xor__(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ... def symmetric_difference_update(self, other: Iterable[_T]) -> None: ... - def __ixor__(self: Self, other: Iterable[_T]) -> Self: ... # type: ignore[override,misc] + def __ixor__(self, other: Iterable[_T]) -> Self: ... # type: ignore[override,misc] def union(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ... def __or__(self, other: Iterable[_S]) -> WeakSet[_S | _T]: ... def isdisjoint(self, other: Iterable[_T]) -> bool: ... diff --git a/mypy/typeshed/stdlib/_winapi.pyi b/mypy/typeshed/stdlib/_winapi.pyi index 5e0087e29934..e21402b801c5 100644 --- a/mypy/typeshed/stdlib/_winapi.pyi +++ b/mypy/typeshed/stdlib/_winapi.pyi @@ -5,13 +5,15 @@ from typing import Any, NoReturn, overload from typing_extensions import Literal, final if sys.platform == "win32": - ABOVE_NORMAL_PRIORITY_CLASS: Literal[32768] - BELOW_NORMAL_PRIORITY_CLASS: Literal[16384] - CREATE_BREAKAWAY_FROM_JOB: Literal[16777216] - CREATE_DEFAULT_ERROR_MODE: Literal[67108864] - CREATE_NO_WINDOW: Literal[134217728] - CREATE_NEW_CONSOLE: Literal[16] - CREATE_NEW_PROCESS_GROUP: Literal[512] + ABOVE_NORMAL_PRIORITY_CLASS: Literal[0x8000] + BELOW_NORMAL_PRIORITY_CLASS: Literal[0x4000] + + CREATE_BREAKAWAY_FROM_JOB: Literal[0x1000000] + CREATE_DEFAULT_ERROR_MODE: Literal[0x4000000] + CREATE_NO_WINDOW: Literal[0x8000000] + CREATE_NEW_CONSOLE: Literal[0x10] + CREATE_NEW_PROCESS_GROUP: Literal[0x200] + DETACHED_PROCESS: Literal[8] DUPLICATE_CLOSE_SOURCE: Literal[1] DUPLICATE_SAME_ACCESS: Literal[2] @@ -28,40 +30,43 @@ if sys.platform == "win32": ERROR_PIPE_CONNECTED: Literal[535] ERROR_SEM_TIMEOUT: Literal[121] - FILE_FLAG_FIRST_PIPE_INSTANCE: Literal[524288] - FILE_FLAG_OVERLAPPED: Literal[1073741824] + FILE_FLAG_FIRST_PIPE_INSTANCE: Literal[0x80000] + FILE_FLAG_OVERLAPPED: Literal[0x40000000] + FILE_GENERIC_READ: Literal[1179785] FILE_GENERIC_WRITE: Literal[1179926] + if sys.version_info >= (3, 8): FILE_MAP_ALL_ACCESS: Literal[983071] FILE_MAP_COPY: Literal[1] FILE_MAP_EXECUTE: Literal[32] FILE_MAP_READ: Literal[4] FILE_MAP_WRITE: Literal[2] + FILE_TYPE_CHAR: Literal[2] FILE_TYPE_DISK: Literal[1] FILE_TYPE_PIPE: Literal[3] FILE_TYPE_REMOTE: Literal[32768] FILE_TYPE_UNKNOWN: Literal[0] - GENERIC_READ: Literal[2147483648] - GENERIC_WRITE: Literal[1073741824] - HIGH_PRIORITY_CLASS: Literal[128] - INFINITE: Literal[4294967295] + GENERIC_READ: Literal[0x80000000] + GENERIC_WRITE: Literal[0x40000000] + HIGH_PRIORITY_CLASS: Literal[0x80] + INFINITE: Literal[0xFFFFFFFF] if sys.version_info >= (3, 8): - INVALID_HANDLE_VALUE: int # very large number - IDLE_PRIORITY_CLASS: Literal[64] - NORMAL_PRIORITY_CLASS: Literal[32] - REALTIME_PRIORITY_CLASS: Literal[256] - NMPWAIT_WAIT_FOREVER: Literal[4294967295] + INVALID_HANDLE_VALUE: Literal[0xFFFFFFFFFFFFFFFF] + IDLE_PRIORITY_CLASS: Literal[0x40] + NORMAL_PRIORITY_CLASS: Literal[0x20] + REALTIME_PRIORITY_CLASS: Literal[0x100] + NMPWAIT_WAIT_FOREVER: Literal[0xFFFFFFFF] if sys.version_info >= (3, 8): - MEM_COMMIT: Literal[4096] - MEM_FREE: Literal[65536] - MEM_IMAGE: Literal[16777216] - MEM_MAPPED: Literal[262144] - MEM_PRIVATE: Literal[131072] - MEM_RESERVE: Literal[8192] + MEM_COMMIT: Literal[0x1000] + MEM_FREE: Literal[0x10000] + MEM_IMAGE: Literal[0x1000000] + MEM_MAPPED: Literal[0x40000] + MEM_PRIVATE: Literal[0x20000] + MEM_RESERVE: Literal[0x2000] NULL: Literal[0] OPEN_EXISTING: Literal[3] @@ -72,37 +77,42 @@ if sys.platform == "win32": PIPE_TYPE_MESSAGE: Literal[4] PIPE_UNLIMITED_INSTANCES: Literal[255] PIPE_WAIT: Literal[0] + if sys.version_info >= (3, 8): - PAGE_EXECUTE: Literal[16] - PAGE_EXECUTE_READ: Literal[32] - PAGE_EXECUTE_READWRITE: Literal[64] - PAGE_EXECUTE_WRITECOPY: Literal[128] - PAGE_GUARD: Literal[256] - PAGE_NOACCESS: Literal[1] - PAGE_NOCACHE: Literal[512] - PAGE_READONLY: Literal[2] - PAGE_READWRITE: Literal[4] - PAGE_WRITECOMBINE: Literal[1024] - PAGE_WRITECOPY: Literal[8] - - PROCESS_ALL_ACCESS: Literal[2097151] - PROCESS_DUP_HANDLE: Literal[64] + PAGE_EXECUTE: Literal[0x10] + PAGE_EXECUTE_READ: Literal[0x20] + PAGE_EXECUTE_READWRITE: Literal[0x40] + PAGE_EXECUTE_WRITECOPY: Literal[0x80] + PAGE_GUARD: Literal[0x100] + PAGE_NOACCESS: Literal[0x1] + PAGE_NOCACHE: Literal[0x200] + PAGE_READONLY: Literal[0x2] + PAGE_READWRITE: Literal[0x4] + PAGE_WRITECOMBINE: Literal[0x400] + PAGE_WRITECOPY: Literal[0x8] + + PROCESS_ALL_ACCESS: Literal[0x1FFFFF] + PROCESS_DUP_HANDLE: Literal[0x40] + if sys.version_info >= (3, 8): - SEC_COMMIT: Literal[134217728] - SEC_IMAGE: Literal[16777216] - SEC_LARGE_PAGES: Literal[2147483648] - SEC_NOCACHE: Literal[268435456] - SEC_RESERVE: Literal[67108864] - SEC_WRITECOMBINE: Literal[1073741824] - STARTF_USESHOWWINDOW: Literal[1] - STARTF_USESTDHANDLES: Literal[256] - STD_ERROR_HANDLE: Literal[4294967284] - STD_INPUT_HANDLE: Literal[4294967286] - STD_OUTPUT_HANDLE: Literal[4294967285] + SEC_COMMIT: Literal[0x8000000] + SEC_IMAGE: Literal[0x1000000] + SEC_LARGE_PAGES: Literal[0x80000000] + SEC_NOCACHE: Literal[0x10000000] + SEC_RESERVE: Literal[0x4000000] + SEC_WRITECOMBINE: Literal[0x40000000] + + STARTF_USESHOWWINDOW: Literal[0x1] + STARTF_USESTDHANDLES: Literal[0x100] + + STD_ERROR_HANDLE: Literal[0xFFFFFFF4] + STD_OUTPUT_HANDLE: Literal[0xFFFFFFF5] + STD_INPUT_HANDLE: Literal[0xFFFFFFF6] + STILL_ACTIVE: Literal[259] SW_HIDE: Literal[0] if sys.version_info >= (3, 8): - SYNCHRONIZE: Literal[1048576] + SYNCHRONIZE: Literal[0x100000] WAIT_ABANDONED_0: Literal[128] WAIT_OBJECT_0: Literal[0] WAIT_TIMEOUT: Literal[258] @@ -196,7 +206,7 @@ if sys.platform == "win32": __named_pipe: int, __mode: int | None, __max_collection_count: int | None, __collect_data_timeout: int | None ) -> None: ... def TerminateProcess(__handle: int, __exit_code: int) -> None: ... - def WaitForMultipleObjects(__handle_seq: Sequence[int], __wait_flag: bool, __milliseconds: int = 4294967295) -> int: ... + def WaitForMultipleObjects(__handle_seq: Sequence[int], __wait_flag: bool, __milliseconds: int = 0xFFFFFFFF) -> int: ... def WaitForSingleObject(__handle: int, __milliseconds: int) -> int: ... def WaitNamedPipe(__name: str, __timeout: int) -> None: ... @overload diff --git a/mypy/typeshed/stdlib/abc.pyi b/mypy/typeshed/stdlib/abc.pyi index 44a5b2289832..068dab4752be 100644 --- a/mypy/typeshed/stdlib/abc.pyi +++ b/mypy/typeshed/stdlib/abc.pyi @@ -1,5 +1,6 @@ +import _typeshed import sys -from _typeshed import Self, SupportsWrite +from _typeshed import SupportsWrite from collections.abc import Callable from typing import Any, Generic, TypeVar from typing_extensions import Literal @@ -13,10 +14,12 @@ class ABCMeta(type): __abstractmethods__: frozenset[str] if sys.version_info >= (3, 11): def __new__( - __mcls: type[Self], __name: str, __bases: tuple[type, ...], __namespace: dict[str, Any], **kwargs: Any - ) -> Self: ... + __mcls: type[_typeshed.Self], __name: str, __bases: tuple[type, ...], __namespace: dict[str, Any], **kwargs: Any + ) -> _typeshed.Self: ... else: - def __new__(mcls: type[Self], name: str, bases: tuple[type, ...], namespace: dict[str, Any], **kwargs: Any) -> Self: ... + def __new__( + mcls: type[_typeshed.Self], name: str, bases: tuple[type, ...], namespace: dict[str, Any], **kwargs: Any + ) -> _typeshed.Self: ... def __instancecheck__(cls: ABCMeta, instance: Any) -> bool: ... def __subclasscheck__(cls: ABCMeta, subclass: type) -> bool: ... diff --git a/mypy/typeshed/stdlib/aifc.pyi b/mypy/typeshed/stdlib/aifc.pyi index ad126d6cdbef..ab0c18ed6623 100644 --- a/mypy/typeshed/stdlib/aifc.pyi +++ b/mypy/typeshed/stdlib/aifc.pyi @@ -1,8 +1,7 @@ import sys -from _typeshed import Self from types import TracebackType from typing import IO, Any, NamedTuple, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias if sys.version_info >= (3, 9): __all__ = ["Error", "open"] @@ -24,7 +23,7 @@ _Marker: TypeAlias = tuple[int, int, bytes] class Aifc_read: def __init__(self, f: _File) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... @@ -48,7 +47,7 @@ class Aifc_read: class Aifc_write: def __init__(self, f: _File) -> None: ... def __del__(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/array.pyi b/mypy/typeshed/stdlib/array.pyi index 25c389c47e8e..827bbb97897f 100644 --- a/mypy/typeshed/stdlib/array.pyi +++ b/mypy/typeshed/stdlib/array.pyi @@ -1,10 +1,10 @@ import sys -from _typeshed import ReadableBuffer, Self, SupportsRead, SupportsWrite +from _typeshed import ReadableBuffer, SupportsRead, SupportsWrite from collections.abc import Iterable # pytype crashes if array inherits from collections.abc.MutableSequence instead of typing.MutableSequence from typing import Any, Generic, MutableSequence, TypeVar, overload # noqa: Y022 -from typing_extensions import Literal, SupportsIndex, TypeAlias +from typing_extensions import Literal, Self, SupportsIndex, TypeAlias _IntTypeCode: TypeAlias = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"] _FloatTypeCode: TypeAlias = Literal["f", "d"] @@ -72,8 +72,8 @@ class array(MutableSequence[_T], Generic[_T]): def __add__(self, __x: array[_T]) -> array[_T]: ... def __ge__(self, __other: array[_T]) -> bool: ... def __gt__(self, __other: array[_T]) -> bool: ... - def __iadd__(self: Self, __x: array[_T]) -> Self: ... # type: ignore[override] - def __imul__(self: Self, __n: int) -> Self: ... + def __iadd__(self, __x: array[_T]) -> Self: ... # type: ignore[override] + def __imul__(self, __n: int) -> Self: ... def __le__(self, __other: array[_T]) -> bool: ... def __lt__(self, __other: array[_T]) -> bool: ... def __mul__(self, __n: int) -> array[_T]: ... diff --git a/mypy/typeshed/stdlib/asyncio/events.pyi b/mypy/typeshed/stdlib/asyncio/events.pyi index b2292801ee0d..f97afe873c9f 100644 --- a/mypy/typeshed/stdlib/asyncio/events.pyi +++ b/mypy/typeshed/stdlib/asyncio/events.pyi @@ -1,12 +1,12 @@ import ssl import sys -from _typeshed import FileDescriptorLike, ReadableBuffer, Self, StrPath, Unused, WriteableBuffer +from _typeshed import FileDescriptorLike, ReadableBuffer, StrPath, Unused, WriteableBuffer from abc import ABCMeta, abstractmethod from collections.abc import Awaitable, Callable, Coroutine, Generator, Sequence from contextvars import Context from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket from typing import IO, Any, Protocol, TypeVar, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias from .base_events import Server from .futures import Future @@ -95,7 +95,7 @@ class TimerHandle(Handle): class AbstractServer: @abstractmethod def close(self) -> None: ... - async def __aenter__(self: Self) -> Self: ... + async def __aenter__(self) -> Self: ... async def __aexit__(self, *exc: Unused) -> None: ... @abstractmethod def get_loop(self) -> AbstractEventLoop: ... @@ -524,11 +524,11 @@ class AbstractEventLoop: stdin: int | IO[Any] | None = -1, stdout: int | IO[Any] | None = -1, stderr: int | IO[Any] | None = -1, - universal_newlines: Literal[False] = ..., - shell: Literal[True] = ..., - bufsize: Literal[0] = ..., - encoding: None = ..., - errors: None = ..., + universal_newlines: Literal[False] = False, + shell: Literal[True] = True, + bufsize: Literal[0] = 0, + encoding: None = None, + errors: None = None, text: Literal[False, None] = ..., **kwargs: Any, ) -> tuple[SubprocessTransport, _ProtocolT]: ... @@ -541,11 +541,11 @@ class AbstractEventLoop: stdin: int | IO[Any] | None = -1, stdout: int | IO[Any] | None = -1, stderr: int | IO[Any] | None = -1, - universal_newlines: Literal[False] = ..., - shell: Literal[False] = ..., - bufsize: Literal[0] = ..., - encoding: None = ..., - errors: None = ..., + universal_newlines: Literal[False] = False, + shell: Literal[False] = False, + bufsize: Literal[0] = 0, + encoding: None = None, + errors: None = None, **kwargs: Any, ) -> tuple[SubprocessTransport, _ProtocolT]: ... @abstractmethod diff --git a/mypy/typeshed/stdlib/asyncio/futures.pyi b/mypy/typeshed/stdlib/asyncio/futures.pyi index f325272d2403..79209f5ed4fb 100644 --- a/mypy/typeshed/stdlib/asyncio/futures.pyi +++ b/mypy/typeshed/stdlib/asyncio/futures.pyi @@ -1,9 +1,8 @@ import sys -from _typeshed import Self from collections.abc import Awaitable, Callable, Generator, Iterable from concurrent.futures._base import Error, Future as _ConcurrentFuture from typing import Any, TypeVar -from typing_extensions import Literal, TypeGuard +from typing_extensions import Literal, Self, TypeGuard from .events import AbstractEventLoop @@ -43,8 +42,8 @@ class Future(Awaitable[_T], Iterable[_T]): def __del__(self) -> None: ... def get_loop(self) -> AbstractEventLoop: ... @property - def _callbacks(self: Self) -> list[tuple[Callable[[Self], Any], Context]]: ... - def add_done_callback(self: Self, __fn: Callable[[Self], object], *, context: Context | None = None) -> None: ... + def _callbacks(self) -> list[tuple[Callable[[Self], Any], Context]]: ... + def add_done_callback(self, __fn: Callable[[Self], object], *, context: Context | None = None) -> None: ... if sys.version_info >= (3, 9): def cancel(self, msg: Any | None = None) -> bool: ... else: @@ -54,7 +53,7 @@ class Future(Awaitable[_T], Iterable[_T]): def done(self) -> bool: ... def result(self) -> _T: ... def exception(self) -> BaseException | None: ... - def remove_done_callback(self: Self, __fn: Callable[[Self], object]) -> int: ... + def remove_done_callback(self, __fn: Callable[[Self], object]) -> int: ... def set_result(self, __result: _T) -> None: ... def set_exception(self, __exception: type | BaseException) -> None: ... def __iter__(self) -> Generator[Any, None, _T]: ... diff --git a/mypy/typeshed/stdlib/asyncio/locks.pyi b/mypy/typeshed/stdlib/asyncio/locks.pyi index 87bcaa2110db..ab4e63ab59b1 100644 --- a/mypy/typeshed/stdlib/asyncio/locks.pyi +++ b/mypy/typeshed/stdlib/asyncio/locks.pyi @@ -1,11 +1,11 @@ import enum import sys -from _typeshed import Self, Unused +from _typeshed import Unused from collections import deque from collections.abc import Callable, Generator from types import TracebackType from typing import Any, TypeVar -from typing_extensions import Literal +from typing_extensions import Literal, Self from .events import AbstractEventLoop from .futures import Future @@ -103,7 +103,7 @@ if sys.version_info >= (3, 11): class Barrier(_LoopBoundMixin): def __init__(self, parties: int) -> None: ... - async def __aenter__(self: Self) -> Self: ... + async def __aenter__(self) -> Self: ... async def __aexit__(self, *args: Unused) -> None: ... async def wait(self) -> int: ... async def abort(self) -> None: ... diff --git a/mypy/typeshed/stdlib/asyncio/runners.pyi b/mypy/typeshed/stdlib/asyncio/runners.pyi index 484f9eb831a1..847072b633ac 100644 --- a/mypy/typeshed/stdlib/asyncio/runners.pyi +++ b/mypy/typeshed/stdlib/asyncio/runners.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import Self, Unused +from _typeshed import Unused from collections.abc import Callable, Coroutine from contextvars import Context from typing import Any, TypeVar -from typing_extensions import final +from typing_extensions import Self, final from .events import AbstractEventLoop @@ -17,7 +17,7 @@ if sys.version_info >= (3, 11): @final class Runner: def __init__(self, *, debug: bool | None = None, loop_factory: Callable[[], AbstractEventLoop] | None = None) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, exc_type: Unused, exc_val: Unused, exc_tb: Unused) -> None: ... def close(self) -> None: ... def get_loop(self) -> AbstractEventLoop: ... diff --git a/mypy/typeshed/stdlib/asyncio/streams.pyi b/mypy/typeshed/stdlib/asyncio/streams.pyi index 2468f482291c..f30c57305d93 100644 --- a/mypy/typeshed/stdlib/asyncio/streams.pyi +++ b/mypy/typeshed/stdlib/asyncio/streams.pyi @@ -1,9 +1,9 @@ import ssl import sys -from _typeshed import Self, StrPath +from _typeshed import StrPath from collections.abc import AsyncIterator, Awaitable, Callable, Iterable, Sequence from typing import Any -from typing_extensions import SupportsIndex, TypeAlias +from typing_extensions import Self, SupportsIndex, TypeAlias from . import events, protocols, transports from .base_events import Server @@ -166,5 +166,5 @@ class StreamReader(AsyncIterator[bytes]): async def readuntil(self, separator: bytes | bytearray | memoryview = b"\n") -> bytes: ... async def read(self, n: int = -1) -> bytes: ... async def readexactly(self, n: int) -> bytes: ... - def __aiter__(self: Self) -> Self: ... + def __aiter__(self) -> Self: ... async def __anext__(self) -> bytes: ... diff --git a/mypy/typeshed/stdlib/asyncio/subprocess.pyi b/mypy/typeshed/stdlib/asyncio/subprocess.pyi index b112a9d80a32..10a414f24537 100644 --- a/mypy/typeshed/stdlib/asyncio/subprocess.pyi +++ b/mypy/typeshed/stdlib/asyncio/subprocess.pyi @@ -49,11 +49,11 @@ if sys.version_info >= (3, 11): limit: int = 65536, *, # These parameters are forced to these values by BaseEventLoop.subprocess_shell - universal_newlines: Literal[False] = ..., - shell: Literal[True] = ..., - bufsize: Literal[0] = ..., - encoding: None = ..., - errors: None = ..., + universal_newlines: Literal[False] = False, + shell: Literal[True] = True, + bufsize: Literal[0] = 0, + encoding: None = None, + errors: None = None, text: Literal[False, None] = ..., # These parameters are taken by subprocess.Popen, which this ultimately delegates to executable: StrOrBytesPath | None = ..., @@ -81,11 +81,11 @@ if sys.version_info >= (3, 11): stderr: int | IO[Any] | None = None, limit: int = 65536, # These parameters are forced to these values by BaseEventLoop.subprocess_shell - universal_newlines: Literal[False] = ..., - shell: Literal[True] = ..., - bufsize: Literal[0] = ..., - encoding: None = ..., - errors: None = ..., + universal_newlines: Literal[False] = False, + shell: Literal[True] = True, + bufsize: Literal[0] = 0, + encoding: None = None, + errors: None = None, # These parameters are taken by subprocess.Popen, which this ultimately delegates to text: bool | None = ..., executable: StrOrBytesPath | None = ..., @@ -115,11 +115,11 @@ elif sys.version_info >= (3, 10): limit: int = 65536, *, # These parameters are forced to these values by BaseEventLoop.subprocess_shell - universal_newlines: Literal[False] = ..., - shell: Literal[True] = ..., - bufsize: Literal[0] = ..., - encoding: None = ..., - errors: None = ..., + universal_newlines: Literal[False] = False, + shell: Literal[True] = True, + bufsize: Literal[0] = 0, + encoding: None = None, + errors: None = None, text: Literal[False, None] = ..., # These parameters are taken by subprocess.Popen, which this ultimately delegates to executable: StrOrBytesPath | None = ..., @@ -146,11 +146,11 @@ elif sys.version_info >= (3, 10): stderr: int | IO[Any] | None = None, limit: int = 65536, # These parameters are forced to these values by BaseEventLoop.subprocess_shell - universal_newlines: Literal[False] = ..., - shell: Literal[True] = ..., - bufsize: Literal[0] = ..., - encoding: None = ..., - errors: None = ..., + universal_newlines: Literal[False] = False, + shell: Literal[True] = True, + bufsize: Literal[0] = 0, + encoding: None = None, + errors: None = None, # These parameters are taken by subprocess.Popen, which this ultimately delegates to text: bool | None = ..., executable: StrOrBytesPath | None = ..., @@ -180,11 +180,11 @@ else: # >= 3.9 limit: int = 65536, *, # These parameters are forced to these values by BaseEventLoop.subprocess_shell - universal_newlines: Literal[False] = ..., - shell: Literal[True] = ..., - bufsize: Literal[0] = ..., - encoding: None = ..., - errors: None = ..., + universal_newlines: Literal[False] = False, + shell: Literal[True] = True, + bufsize: Literal[0] = 0, + encoding: None = None, + errors: None = None, text: Literal[False, None] = ..., # These parameters are taken by subprocess.Popen, which this ultimately delegates to executable: StrOrBytesPath | None = ..., @@ -211,11 +211,11 @@ else: # >= 3.9 loop: events.AbstractEventLoop | None = None, limit: int = 65536, # These parameters are forced to these values by BaseEventLoop.subprocess_shell - universal_newlines: Literal[False] = ..., - shell: Literal[True] = ..., - bufsize: Literal[0] = ..., - encoding: None = ..., - errors: None = ..., + universal_newlines: Literal[False] = False, + shell: Literal[True] = True, + bufsize: Literal[0] = 0, + encoding: None = None, + errors: None = None, # These parameters are taken by subprocess.Popen, which this ultimately delegates to text: bool | None = ..., executable: StrOrBytesPath | None = ..., diff --git a/mypy/typeshed/stdlib/asyncio/taskgroups.pyi b/mypy/typeshed/stdlib/asyncio/taskgroups.pyi index 9e6c6e047368..8daa96f1ede0 100644 --- a/mypy/typeshed/stdlib/asyncio/taskgroups.pyi +++ b/mypy/typeshed/stdlib/asyncio/taskgroups.pyi @@ -1,10 +1,10 @@ # This only exists in 3.11+. See VERSIONS. -from _typeshed import Self from collections.abc import Coroutine, Generator from contextvars import Context from types import TracebackType from typing import Any, TypeVar +from typing_extensions import Self from .tasks import Task @@ -13,7 +13,7 @@ __all__ = ["TaskGroup"] _T = TypeVar("_T") class TaskGroup: - async def __aenter__(self: Self) -> Self: ... + async def __aenter__(self) -> Self: ... async def __aexit__(self, et: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None: ... def create_task( self, coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T], *, name: str | None = None, context: Context | None = None diff --git a/mypy/typeshed/stdlib/asyncio/timeouts.pyi b/mypy/typeshed/stdlib/asyncio/timeouts.pyi index be516b5851d1..2d31b777b77d 100644 --- a/mypy/typeshed/stdlib/asyncio/timeouts.pyi +++ b/mypy/typeshed/stdlib/asyncio/timeouts.pyi @@ -1,6 +1,5 @@ -from _typeshed import Self from types import TracebackType -from typing_extensions import final +from typing_extensions import Self, final __all__ = ("Timeout", "timeout", "timeout_at") @@ -10,7 +9,7 @@ class Timeout: def when(self) -> float | None: ... def reschedule(self, when: float | None) -> None: ... def expired(self) -> bool: ... - async def __aenter__(self: Self) -> Self: ... + async def __aenter__(self) -> Self: ... async def __aexit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/asyncio/unix_events.pyi b/mypy/typeshed/stdlib/asyncio/unix_events.pyi index 5e2b05f57ef1..e28d64b5287b 100644 --- a/mypy/typeshed/stdlib/asyncio/unix_events.pyi +++ b/mypy/typeshed/stdlib/asyncio/unix_events.pyi @@ -1,10 +1,9 @@ import sys import types -from _typeshed import Self from abc import ABCMeta, abstractmethod from collections.abc import Callable from typing import Any -from typing_extensions import Literal +from typing_extensions import Literal, Self from .events import AbstractEventLoop, BaseDefaultEventLoopPolicy from .selector_events import BaseSelectorEventLoop @@ -22,7 +21,7 @@ class AbstractChildWatcher: @abstractmethod def close(self) -> None: ... @abstractmethod - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... @abstractmethod def __exit__(self, typ: type[BaseException] | None, exc: BaseException | None, tb: types.TracebackType | None) -> None: ... if sys.version_info >= (3, 8): @@ -64,13 +63,13 @@ if sys.platform != "win32": def attach_loop(self, loop: AbstractEventLoop | None) -> None: ... class SafeChildWatcher(BaseChildWatcher): - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None) -> None: ... def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ... def remove_child_handler(self, pid: int) -> bool: ... class FastChildWatcher(BaseChildWatcher): - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None) -> None: ... def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ... def remove_child_handler(self, pid: int) -> bool: ... @@ -95,7 +94,7 @@ if sys.platform != "win32": class MultiLoopChildWatcher(AbstractChildWatcher): def is_active(self) -> bool: ... def close(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... @@ -106,7 +105,7 @@ if sys.platform != "win32": class ThreadedChildWatcher(AbstractChildWatcher): def is_active(self) -> Literal[True]: ... def close(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... @@ -117,7 +116,7 @@ if sys.platform != "win32": if sys.version_info >= (3, 9): class PidfdChildWatcher(AbstractChildWatcher): - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/asyncio/windows_utils.pyi b/mypy/typeshed/stdlib/asyncio/windows_utils.pyi index 6ac4e0d89aa4..f3a82e2b8462 100644 --- a/mypy/typeshed/stdlib/asyncio/windows_utils.pyi +++ b/mypy/typeshed/stdlib/asyncio/windows_utils.pyi @@ -1,10 +1,9 @@ import subprocess import sys -from _typeshed import Self from collections.abc import Callable from types import TracebackType from typing import Any, AnyStr, Protocol -from typing_extensions import Literal +from typing_extensions import Literal, Self if sys.platform == "win32": __all__ = ("pipe", "Popen", "PIPE", "PipeHandle") @@ -25,7 +24,7 @@ if sys.platform == "win32": else: def __del__(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, t: type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ... @property def handle(self) -> int: ... @@ -41,7 +40,7 @@ if sys.platform == "win32": # subprocess.Popen takes other positional-or-keyword arguments before # stdin. def __new__( - cls: type[Self], + cls, args: subprocess._CMD, stdin: subprocess._FILE | None = ..., stdout: subprocess._FILE | None = ..., diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi index 9f45a937764b..7b8e25084c91 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -1,4 +1,5 @@ import _ast +import _typeshed import sys import types from _collections_abc import dict_items, dict_keys, dict_values @@ -11,7 +12,6 @@ from _typeshed import ( OpenBinaryModeWriting, OpenTextMode, ReadableBuffer, - Self, SupportsAdd, SupportsAiter, SupportsAnext, @@ -54,7 +54,7 @@ from typing import ( # noqa: Y022 overload, type_check_only, ) -from typing_extensions import Literal, SupportsIndex, TypeAlias, TypeGuard, final +from typing_extensions import Literal, Self, SupportsIndex, TypeAlias, TypeGuard, final if sys.version_info >= (3, 9): from types import GenericAlias @@ -82,12 +82,12 @@ class object: __module__: str __annotations__: dict[str, Any] @property - def __class__(self: Self) -> type[Self]: ... + def __class__(self) -> type[Self]: ... # Ignore errors about type mismatch between property getter and setter @__class__.setter def __class__(self, __type: type[object]) -> None: ... # noqa: F811 def __init__(self) -> None: ... - def __new__(cls: type[Self]) -> Self: ... + def __new__(cls) -> Self: ... # N.B. `object.__setattr__` and `object.__delattr__` are heavily special-cased by type checkers. # Overriding them in subclasses has different semantics, even if the override has an identical signature. def __setattr__(self, __name: str, __value: Any) -> None: ... @@ -168,9 +168,11 @@ class type: @overload def __new__(cls, __o: object) -> type: ... @overload - def __new__(cls: type[Self], __name: str, __bases: tuple[type, ...], __namespace: dict[str, Any], **kwds: Any) -> Self: ... + def __new__( + cls: type[_typeshed.Self], __name: str, __bases: tuple[type, ...], __namespace: dict[str, Any], **kwds: Any + ) -> _typeshed.Self: ... def __call__(self, *args: Any, **kwds: Any) -> Any: ... - def __subclasses__(self: Self) -> list[Self]: ... + def __subclasses__(self: _typeshed.Self) -> list[_typeshed.Self]: ... # Note: the documentation doesn't specify what the return type is, the standard # implementation seems to be returning a list. def mro(self) -> list[type]: ... @@ -196,9 +198,9 @@ _LiteralInteger = _PositiveInteger | _NegativeInteger | Literal[0] # noqa: Y026 class int: @overload - def __new__(cls: type[Self], __x: str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc = ...) -> Self: ... + def __new__(cls, __x: str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc = ...) -> Self: ... @overload - def __new__(cls: type[Self], __x: str | bytes | bytearray, base: SupportsIndex) -> Self: ... + def __new__(cls, __x: str | bytes | bytearray, base: SupportsIndex) -> Self: ... if sys.version_info >= (3, 8): def as_integer_ratio(self) -> tuple[int, Literal[1]]: ... @@ -221,7 +223,7 @@ class int: ) -> bytes: ... @classmethod def from_bytes( - cls: type[Self], + cls, bytes: Iterable[SupportsIndex] | SupportsBytes | ReadableBuffer, byteorder: Literal["little", "big"] = "big", *, @@ -231,7 +233,7 @@ class int: def to_bytes(self, length: SupportsIndex, byteorder: Literal["little", "big"], *, signed: bool = False) -> bytes: ... @classmethod def from_bytes( - cls: type[Self], + cls, bytes: Iterable[SupportsIndex] | SupportsBytes | ReadableBuffer, byteorder: Literal["little", "big"], *, @@ -257,13 +259,13 @@ class int: @overload def __pow__(self, __x: Literal[0], __modulo: None) -> Literal[1]: ... @overload - def __pow__(self, __x: _PositiveInteger, __modulo: None = ...) -> int: ... + def __pow__(self, __x: _PositiveInteger, __modulo: None = None) -> int: ... @overload - def __pow__(self, __x: _NegativeInteger, __modulo: None = ...) -> float: ... + def __pow__(self, __x: _NegativeInteger, __modulo: None = None) -> float: ... # positive x -> int; negative x -> float # return type must be Any as `int | float` causes too many false-positive errors @overload - def __pow__(self, __x: int, __modulo: None = ...) -> Any: ... + def __pow__(self, __x: int, __modulo: None = None) -> Any: ... @overload def __pow__(self, __x: int, __modulo: int) -> int: ... def __rpow__(self, __x: int, __mod: int | None = None) -> Any: ... @@ -298,12 +300,12 @@ class int: def __index__(self) -> int: ... class float: - def __new__(cls: type[Self], __x: SupportsFloat | SupportsIndex | str | ReadableBuffer = ...) -> Self: ... + def __new__(cls, __x: SupportsFloat | SupportsIndex | str | ReadableBuffer = ...) -> Self: ... def as_integer_ratio(self) -> tuple[int, int]: ... def hex(self) -> str: ... def is_integer(self) -> bool: ... @classmethod - def fromhex(cls: type[Self], __s: str) -> Self: ... + def fromhex(cls, __s: str) -> Self: ... @property def real(self) -> float: ... @property @@ -330,7 +332,7 @@ class float: def __rmod__(self, __x: float) -> float: ... def __rdivmod__(self, __x: float) -> tuple[float, float]: ... @overload - def __rpow__(self, __x: _PositiveInteger, __modulo: None = ...) -> float: ... + def __rpow__(self, __x: _PositiveInteger, __modulo: None = None) -> float: ... @overload def __rpow__(self, __x: _NegativeInteger, __mod: None = None) -> complex: ... # Returning `complex` for the general case gives too many false-positive errors. @@ -364,19 +366,17 @@ class complex: # Python doesn't currently accept SupportsComplex for the second argument @overload def __new__( - cls: type[Self], + cls, real: complex | SupportsComplex | SupportsFloat | SupportsIndex = ..., imag: complex | SupportsFloat | SupportsIndex = ..., ) -> Self: ... @overload - def __new__(cls: type[Self], real: str | SupportsComplex | SupportsFloat | SupportsIndex | complex) -> Self: ... + def __new__(cls, real: str | SupportsComplex | SupportsFloat | SupportsIndex | complex) -> Self: ... else: @overload - def __new__( - cls: type[Self], real: complex | SupportsComplex | SupportsFloat = ..., imag: complex | SupportsFloat = ... - ) -> Self: ... + def __new__(cls, real: complex | SupportsComplex | SupportsFloat = ..., imag: complex | SupportsFloat = ...) -> Self: ... @overload - def __new__(cls: type[Self], real: str | SupportsComplex | SupportsFloat | complex) -> Self: ... + def __new__(cls, real: str | SupportsComplex | SupportsFloat | complex) -> Self: ... @property def real(self) -> float: ... @@ -410,9 +410,9 @@ class _TranslateTable(Protocol): class str(Sequence[str]): @overload - def __new__(cls: type[Self], object: object = ...) -> Self: ... + def __new__(cls, object: object = ...) -> Self: ... @overload - def __new__(cls: type[Self], object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ... + def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ... def capitalize(self) -> str: ... # type: ignore[misc] def casefold(self) -> str: ... # type: ignore[misc] def center(self, __width: SupportsIndex, __fillchar: str = " ") -> str: ... # type: ignore[misc] @@ -497,11 +497,11 @@ class str(Sequence[str]): class bytes(ByteString): @overload - def __new__(cls: type[Self], __o: Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer) -> Self: ... + def __new__(cls, __o: Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer) -> Self: ... @overload - def __new__(cls: type[Self], __string: str, encoding: str, errors: str = ...) -> Self: ... + def __new__(cls, __string: str, encoding: str, errors: str = ...) -> Self: ... @overload - def __new__(cls: type[Self]) -> Self: ... + def __new__(cls) -> Self: ... def capitalize(self) -> bytes: ... def center(self, __width: SupportsIndex, __fillchar: bytes = b" ") -> bytes: ... def count( @@ -573,7 +573,7 @@ class bytes(ByteString): def upper(self) -> bytes: ... def zfill(self, __width: SupportsIndex) -> bytes: ... @classmethod - def fromhex(cls: type[Self], __s: str) -> Self: ... + def fromhex(cls, __s: str) -> Self: ... @staticmethod def maketrans(__frm: ReadableBuffer, __to: ReadableBuffer) -> bytes: ... def __len__(self) -> int: ... @@ -682,7 +682,7 @@ class bytearray(MutableSequence[int], ByteString): def upper(self) -> bytearray: ... def zfill(self, __width: SupportsIndex) -> bytearray: ... @classmethod - def fromhex(cls: type[Self], __string: str) -> Self: ... + def fromhex(cls, __string: str) -> Self: ... @staticmethod def maketrans(__frm: ReadableBuffer, __to: ReadableBuffer) -> bytes: ... def __len__(self) -> int: ... @@ -699,10 +699,10 @@ class bytearray(MutableSequence[int], ByteString): def __delitem__(self, __i: SupportsIndex | slice) -> None: ... def __add__(self, __s: ReadableBuffer) -> bytearray: ... # The superclass wants us to accept Iterable[int], but that fails at runtime. - def __iadd__(self: Self, __s: ReadableBuffer) -> Self: ... # type: ignore[override] + def __iadd__(self, __s: ReadableBuffer) -> Self: ... # type: ignore[override] def __mul__(self, __n: SupportsIndex) -> bytearray: ... def __rmul__(self, __n: SupportsIndex) -> bytearray: ... - def __imul__(self: Self, __n: SupportsIndex) -> Self: ... + def __imul__(self, __n: SupportsIndex) -> Self: ... def __mod__(self, __value: Any) -> bytes: ... # Incompatible with Sequence.__contains__ def __contains__(self, __o: SupportsIndex | ReadableBuffer) -> bool: ... # type: ignore[override] @@ -741,7 +741,7 @@ class memoryview(Sequence[int]): @property def nbytes(self) -> int: ... def __init__(self, obj: ReadableBuffer) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, __exc_type: type[BaseException] | None, __exc_val: BaseException | None, __exc_tb: TracebackType | None ) -> None: ... @@ -776,7 +776,7 @@ class memoryview(Sequence[int]): @final class bool(int): - def __new__(cls: type[Self], __o: object = ...) -> Self: ... + def __new__(cls, __o: object = ...) -> Self: ... # The following overloads could be represented more elegantly with a TypeVar("_B", bool, int), # however mypy has a bug regarding TypeVar constraints (https://github.com/python/mypy/issues/11880). @overload @@ -821,7 +821,7 @@ class slice: def indices(self, __len: SupportsIndex) -> tuple[int, int, int]: ... class tuple(Sequence[_T_co], Generic[_T_co]): - def __new__(cls: type[Self], __iterable: Iterable[_T_co] = ...) -> Self: ... + def __new__(cls, __iterable: Iterable[_T_co] = ...) -> Self: ... def __len__(self) -> int: ... def __contains__(self, __x: object) -> bool: ... @overload @@ -909,10 +909,10 @@ class list(MutableSequence[_T], Generic[_T]): def __add__(self, __x: list[_T]) -> list[_T]: ... @overload def __add__(self, __x: list[_S]) -> list[_S | _T]: ... - def __iadd__(self: Self, __x: Iterable[_T]) -> Self: ... # type: ignore[misc] + def __iadd__(self, __x: Iterable[_T]) -> Self: ... # type: ignore[misc] def __mul__(self, __n: SupportsIndex) -> list[_T]: ... def __rmul__(self, __n: SupportsIndex) -> list[_T]: ... - def __imul__(self: Self, __n: SupportsIndex) -> Self: ... + def __imul__(self, __n: SupportsIndex) -> Self: ... def __contains__(self, __o: object) -> bool: ... def __reversed__(self) -> Iterator[_T]: ... def __gt__(self, __x: list[_T]) -> bool: ... @@ -941,7 +941,7 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): # Cannot be Iterable[Sequence[_T]] or otherwise dict(["foo", "bar", "baz"]) is not an error @overload def __init__(self: dict[str, str], __iterable: Iterable[list[str]]) -> None: ... - def __new__(cls: type[Self], *args: Any, **kwargs: Any) -> Self: ... + def __new__(cls, *args: Any, **kwargs: Any) -> Self: ... def copy(self) -> dict[_KT, _VT]: ... def keys(self) -> dict_keys[_KT, _VT]: ... def values(self) -> dict_values[_KT, _VT]: ... @@ -978,9 +978,9 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __ror__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ... # dict.__ior__ should be kept roughly in line with MutableMapping.update() @overload # type: ignore[misc] - def __ior__(self: Self, __value: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... + def __ior__(self, __value: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... @overload - def __ior__(self: Self, __value: Iterable[tuple[_KT, _VT]]) -> Self: ... + def __ior__(self, __value: Iterable[tuple[_KT, _VT]]) -> Self: ... class set(MutableSet[_T], Generic[_T]): @overload @@ -1006,13 +1006,13 @@ class set(MutableSet[_T], Generic[_T]): def __contains__(self, __o: object) -> bool: ... def __iter__(self) -> Iterator[_T]: ... def __and__(self, __s: AbstractSet[object]) -> set[_T]: ... - def __iand__(self: Self, __s: AbstractSet[object]) -> Self: ... + def __iand__(self, __s: AbstractSet[object]) -> Self: ... def __or__(self, __s: AbstractSet[_S]) -> set[_T | _S]: ... - def __ior__(self: Self, __s: AbstractSet[_T]) -> Self: ... # type: ignore[override,misc] + def __ior__(self, __s: AbstractSet[_T]) -> Self: ... # type: ignore[override,misc] def __sub__(self, __s: AbstractSet[_T | None]) -> set[_T]: ... - def __isub__(self: Self, __s: AbstractSet[object]) -> Self: ... + def __isub__(self, __s: AbstractSet[object]) -> Self: ... def __xor__(self, __s: AbstractSet[_S]) -> set[_T | _S]: ... - def __ixor__(self: Self, __s: AbstractSet[_T]) -> Self: ... # type: ignore[override,misc] + def __ixor__(self, __s: AbstractSet[_T]) -> Self: ... # type: ignore[override,misc] def __le__(self, __s: AbstractSet[object]) -> bool: ... def __lt__(self, __s: AbstractSet[object]) -> bool: ... def __ge__(self, __s: AbstractSet[object]) -> bool: ... @@ -1023,9 +1023,9 @@ class set(MutableSet[_T], Generic[_T]): class frozenset(AbstractSet[_T_co], Generic[_T_co]): @overload - def __new__(cls: type[Self]) -> Self: ... + def __new__(cls) -> Self: ... @overload - def __new__(cls: type[Self], __iterable: Iterable[_T_co]) -> Self: ... + def __new__(cls, __iterable: Iterable[_T_co]) -> Self: ... def copy(self) -> frozenset[_T_co]: ... def difference(self, *s: Iterable[object]) -> frozenset[_T_co]: ... def intersection(self, *s: Iterable[object]) -> frozenset[_T_co]: ... @@ -1050,7 +1050,7 @@ class frozenset(AbstractSet[_T_co], Generic[_T_co]): class enumerate(Iterator[tuple[int, _T]], Generic[_T]): def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> tuple[int, _T]: ... if sys.version_info >= (3, 9): def __class_getitem__(cls, __item: Any) -> GenericAlias: ... @@ -1143,7 +1143,7 @@ if sys.version_info >= (3, 8): filename: str | ReadableBuffer | _PathLike[Any], mode: str, flags: Literal[0], - dont_inherit: int = False, + dont_inherit: bool = False, optimize: int = -1, *, _feature_version: int = -1, @@ -1154,7 +1154,7 @@ if sys.version_info >= (3, 8): filename: str | ReadableBuffer | _PathLike[Any], mode: str, *, - dont_inherit: int = False, + dont_inherit: bool = False, optimize: int = -1, _feature_version: int = -1, ) -> CodeType: ... @@ -1164,7 +1164,7 @@ if sys.version_info >= (3, 8): filename: str | ReadableBuffer | _PathLike[Any], mode: str, flags: Literal[1024], - dont_inherit: int = False, + dont_inherit: bool = False, optimize: int = -1, *, _feature_version: int = -1, @@ -1175,7 +1175,7 @@ if sys.version_info >= (3, 8): filename: str | ReadableBuffer | _PathLike[Any], mode: str, flags: int, - dont_inherit: int = False, + dont_inherit: bool = False, optimize: int = -1, *, _feature_version: int = -1, @@ -1188,7 +1188,7 @@ else: filename: str | ReadableBuffer | _PathLike[Any], mode: str, flags: Literal[0], - dont_inherit: int = False, + dont_inherit: bool = False, optimize: int = -1, ) -> CodeType: ... @overload @@ -1197,7 +1197,7 @@ else: filename: str | ReadableBuffer | _PathLike[Any], mode: str, *, - dont_inherit: int = False, + dont_inherit: bool = False, optimize: int = -1, ) -> CodeType: ... @overload @@ -1206,7 +1206,7 @@ else: filename: str | ReadableBuffer | _PathLike[Any], mode: str, flags: Literal[1024], - dont_inherit: int = False, + dont_inherit: bool = False, optimize: int = -1, ) -> _ast.AST: ... @overload @@ -1215,7 +1215,7 @@ else: filename: str | ReadableBuffer | _PathLike[Any], mode: str, flags: int, - dont_inherit: int = False, + dont_inherit: bool = False, optimize: int = -1, ) -> Any: ... @@ -1262,7 +1262,7 @@ class filter(Iterator[_T], Generic[_T]): def __init__(self, __function: Callable[[_S], TypeGuard[_T]], __iterable: Iterable[_S]) -> None: ... @overload def __init__(self, __function: Callable[[_T], Any], __iterable: Iterable[_T]) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T: ... def format(__value: object, __format_spec: str = "") -> str: ... @@ -1288,7 +1288,7 @@ def hash(__obj: object) -> int: ... def help(request: object = ...) -> None: ... def hex(__number: int | SupportsIndex) -> str: ... def id(__obj: object) -> int: ... -def input(__prompt: object = None) -> str: ... +def input(__prompt: object = "") -> str: ... class _GetItemIterable(Protocol[_T_co]): def __getitem__(self, __i: int) -> _T_co: ... @@ -1353,35 +1353,35 @@ class map(Iterator[_S], Generic[_S]): __iter6: Iterable[Any], *iterables: Iterable[Any], ) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _S: ... @overload def max( - __arg1: SupportsRichComparisonT, __arg2: SupportsRichComparisonT, *_args: SupportsRichComparisonT, key: None = ... + __arg1: SupportsRichComparisonT, __arg2: SupportsRichComparisonT, *_args: SupportsRichComparisonT, key: None = None ) -> SupportsRichComparisonT: ... @overload def max(__arg1: _T, __arg2: _T, *_args: _T, key: Callable[[_T], SupportsRichComparison]) -> _T: ... @overload -def max(__iterable: Iterable[SupportsRichComparisonT], *, key: None = ...) -> SupportsRichComparisonT: ... +def max(__iterable: Iterable[SupportsRichComparisonT], *, key: None = None) -> SupportsRichComparisonT: ... @overload def max(__iterable: Iterable[_T], *, key: Callable[[_T], SupportsRichComparison]) -> _T: ... @overload -def max(__iterable: Iterable[SupportsRichComparisonT], *, key: None = ..., default: _T) -> SupportsRichComparisonT | _T: ... +def max(__iterable: Iterable[SupportsRichComparisonT], *, key: None = None, default: _T) -> SupportsRichComparisonT | _T: ... @overload def max(__iterable: Iterable[_T1], *, key: Callable[[_T1], SupportsRichComparison], default: _T2) -> _T1 | _T2: ... @overload def min( - __arg1: SupportsRichComparisonT, __arg2: SupportsRichComparisonT, *_args: SupportsRichComparisonT, key: None = ... + __arg1: SupportsRichComparisonT, __arg2: SupportsRichComparisonT, *_args: SupportsRichComparisonT, key: None = None ) -> SupportsRichComparisonT: ... @overload def min(__arg1: _T, __arg2: _T, *_args: _T, key: Callable[[_T], SupportsRichComparison]) -> _T: ... @overload -def min(__iterable: Iterable[SupportsRichComparisonT], *, key: None = ...) -> SupportsRichComparisonT: ... +def min(__iterable: Iterable[SupportsRichComparisonT], *, key: None = None) -> SupportsRichComparisonT: ... @overload def min(__iterable: Iterable[_T], *, key: Callable[[_T], SupportsRichComparison]) -> _T: ... @overload -def min(__iterable: Iterable[SupportsRichComparisonT], *, key: None = ..., default: _T) -> SupportsRichComparisonT | _T: ... +def min(__iterable: Iterable[SupportsRichComparisonT], *, key: None = None, default: _T) -> SupportsRichComparisonT | _T: ... @overload def min(__iterable: Iterable[_T1], *, key: Callable[[_T1], SupportsRichComparison], default: _T2) -> _T1 | _T2: ... @overload @@ -1503,7 +1503,7 @@ class _SupportsPow2(Protocol[_E, _T_co]): def __pow__(self, __other: _E) -> _T_co: ... class _SupportsPow3NoneOnly(Protocol[_E, _T_co]): - def __pow__(self, __other: _E, __modulo: None = ...) -> _T_co: ... + def __pow__(self, __other: _E, __modulo: None = None) -> _T_co: ... class _SupportsPow3(Protocol[_E, _M, _T_co]): def __pow__(self, __other: _E, __modulo: _M) -> _T_co: ... @@ -1590,7 +1590,7 @@ class reversed(Iterator[_T], Generic[_T]): def __init__(self, __sequence: Reversible[_T]) -> None: ... @overload def __init__(self, __sequence: SupportsLenAndGetItem[_T]) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T: ... def __length_hint__(self) -> int: ... @@ -1734,7 +1734,7 @@ class zip(Iterator[_T_co], Generic[_T_co]): *iterables: Iterable[Any], ) -> zip[tuple[Any, ...]]: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... # Signature of `builtins.__import__` should be kept identical to `importlib.__import__` @@ -1764,7 +1764,7 @@ class BaseException: __traceback__: TracebackType | None def __init__(self, *args: object) -> None: ... def __setstate__(self, __state: dict[str, Any] | None) -> None: ... - def with_traceback(self: Self, __tb: TracebackType | None) -> Self: ... + def with_traceback(self, __tb: TracebackType | None) -> Self: ... if sys.version_info >= (3, 11): # only present after add_note() is called __notes__: list[str] @@ -1917,7 +1917,7 @@ if sys.version_info >= (3, 11): # See `check_exception_group.py` for use-cases and comments. class BaseExceptionGroup(BaseException, Generic[_BaseExceptionT_co]): - def __new__(cls: type[Self], __message: str, __exceptions: Sequence[_BaseExceptionT_co]) -> Self: ... + def __new__(cls, __message: str, __exceptions: Sequence[_BaseExceptionT_co]) -> Self: ... def __init__(self, __message: str, __exceptions: Sequence[_BaseExceptionT_co]) -> None: ... @property def message(self) -> str: ... @@ -1933,7 +1933,7 @@ if sys.version_info >= (3, 11): ) -> BaseExceptionGroup[_BaseExceptionT] | None: ... @overload def subgroup( - self: Self, __condition: Callable[[_BaseExceptionT_co | Self], bool] + self, __condition: Callable[[_BaseExceptionT_co | Self], bool] ) -> BaseExceptionGroup[_BaseExceptionT_co] | None: ... @overload def split( @@ -1945,7 +1945,7 @@ if sys.version_info >= (3, 11): ) -> tuple[BaseExceptionGroup[_BaseExceptionT] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]: ... @overload def split( - self: Self, __condition: Callable[[_BaseExceptionT_co | Self], bool] + self, __condition: Callable[[_BaseExceptionT_co | Self], bool] ) -> tuple[BaseExceptionGroup[_BaseExceptionT_co] | None, BaseExceptionGroup[_BaseExceptionT_co] | None]: ... # In reality it is `NonEmptySequence`: @overload @@ -1955,7 +1955,7 @@ if sys.version_info >= (3, 11): def __class_getitem__(cls, __item: Any) -> GenericAlias: ... class ExceptionGroup(BaseExceptionGroup[_ExceptionT_co], Exception): - def __new__(cls: type[Self], __message: str, __exceptions: Sequence[_ExceptionT_co]) -> Self: ... + def __new__(cls, __message: str, __exceptions: Sequence[_ExceptionT_co]) -> Self: ... def __init__(self, __message: str, __exceptions: Sequence[_ExceptionT_co]) -> None: ... @property def exceptions(self) -> tuple[_ExceptionT_co | ExceptionGroup[_ExceptionT_co], ...]: ... @@ -1965,14 +1965,12 @@ if sys.version_info >= (3, 11): self, __condition: type[_ExceptionT] | tuple[type[_ExceptionT], ...] ) -> ExceptionGroup[_ExceptionT] | None: ... @overload - def subgroup( - self: Self, __condition: Callable[[_ExceptionT_co | Self], bool] - ) -> ExceptionGroup[_ExceptionT_co] | None: ... + def subgroup(self, __condition: Callable[[_ExceptionT_co | Self], bool]) -> ExceptionGroup[_ExceptionT_co] | None: ... @overload # type: ignore[override] def split( self, __condition: type[_ExceptionT] | tuple[type[_ExceptionT], ...] ) -> tuple[ExceptionGroup[_ExceptionT] | None, ExceptionGroup[_ExceptionT_co] | None]: ... @overload def split( - self: Self, __condition: Callable[[_ExceptionT_co | Self], bool] + self, __condition: Callable[[_ExceptionT_co | Self], bool] ) -> tuple[ExceptionGroup[_ExceptionT_co] | None, ExceptionGroup[_ExceptionT_co] | None]: ... diff --git a/mypy/typeshed/stdlib/bz2.pyi b/mypy/typeshed/stdlib/bz2.pyi index 8a7151d9e456..9ad80ee6f731 100644 --- a/mypy/typeshed/stdlib/bz2.pyi +++ b/mypy/typeshed/stdlib/bz2.pyi @@ -1,10 +1,10 @@ import _compression import sys from _compression import BaseStream -from _typeshed import ReadableBuffer, Self, StrOrBytesPath, WriteableBuffer +from _typeshed import ReadableBuffer, StrOrBytesPath, WriteableBuffer from collections.abc import Iterable from typing import IO, Any, Protocol, TextIO, overload -from typing_extensions import Literal, SupportsIndex, TypeAlias, final +from typing_extensions import Literal, Self, SupportsIndex, TypeAlias, final __all__ = ["BZ2File", "BZ2Compressor", "BZ2Decompressor", "open", "compress", "decompress"] @@ -92,7 +92,7 @@ def open( ) -> BZ2File | TextIO: ... class BZ2File(BaseStream, IO[bytes]): - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... if sys.version_info >= (3, 9): @overload def __init__(self, filename: _WritableFileobj, mode: _WriteBinaryMode, *, compresslevel: int = 9) -> None: ... diff --git a/mypy/typeshed/stdlib/cProfile.pyi b/mypy/typeshed/stdlib/cProfile.pyi index 77608b268f6f..8945b21427ab 100644 --- a/mypy/typeshed/stdlib/cProfile.pyi +++ b/mypy/typeshed/stdlib/cProfile.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import Self, StrOrBytesPath, Unused +from _typeshed import StrOrBytesPath, Unused from collections.abc import Callable from types import CodeType from typing import Any, TypeVar -from typing_extensions import ParamSpec, TypeAlias +from typing_extensions import ParamSpec, Self, TypeAlias __all__ = ["run", "runctx", "Profile"] @@ -27,11 +27,11 @@ class Profile: def dump_stats(self, file: StrOrBytesPath) -> None: ... def create_stats(self) -> None: ... def snapshot_stats(self) -> None: ... - def run(self: Self, cmd: str) -> Self: ... - def runctx(self: Self, cmd: str, globals: dict[str, Any], locals: dict[str, Any]) -> Self: ... + def run(self, cmd: str) -> Self: ... + def runctx(self, cmd: str, globals: dict[str, Any], locals: dict[str, Any]) -> Self: ... def runcall(self, __func: Callable[_P, _T], *args: _P.args, **kw: _P.kwargs) -> _T: ... if sys.version_info >= (3, 8): - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *exc_info: Unused) -> None: ... def label(code: str | CodeType) -> _Label: ... # undocumented diff --git a/mypy/typeshed/stdlib/cgi.pyi b/mypy/typeshed/stdlib/cgi.pyi index 6f5637e3cce1..a2acfa92d463 100644 --- a/mypy/typeshed/stdlib/cgi.pyi +++ b/mypy/typeshed/stdlib/cgi.pyi @@ -1,10 +1,11 @@ import sys -from _typeshed import Self, SupportsGetItem, SupportsItemAccess, Unused +from _typeshed import SupportsGetItem, SupportsItemAccess, Unused from builtins import list as _list, type as _type from collections.abc import Iterable, Iterator, Mapping from email.message import Message from types import TracebackType from typing import IO, Any, Protocol +from typing_extensions import Self __all__ = [ "MiniFieldStorage", @@ -105,7 +106,7 @@ class FieldStorage: max_num_fields: int | None = None, separator: str = "&", ) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... def __iter__(self) -> Iterator[str]: ... def __getitem__(self, key: str) -> Any: ... diff --git a/mypy/typeshed/stdlib/cgitb.pyi b/mypy/typeshed/stdlib/cgitb.pyi index 04bcbfb0d13d..4c315bf6ca39 100644 --- a/mypy/typeshed/stdlib/cgitb.pyi +++ b/mypy/typeshed/stdlib/cgitb.pyi @@ -2,8 +2,9 @@ from _typeshed import OptExcInfo, StrOrBytesPath from collections.abc import Callable from types import FrameType, TracebackType from typing import IO, Any +from typing_extensions import Final -__UNDEF__: object # undocumented sentinel +__UNDEF__: Final[object] # undocumented sentinel def reset() -> str: ... # undocumented def small(text: str) -> str: ... # undocumented diff --git a/mypy/typeshed/stdlib/codecs.pyi b/mypy/typeshed/stdlib/codecs.pyi index 33d0e6709923..5a22853b6aee 100644 --- a/mypy/typeshed/stdlib/codecs.pyi +++ b/mypy/typeshed/stdlib/codecs.pyi @@ -1,11 +1,11 @@ import sys import types from _codecs import * -from _typeshed import ReadableBuffer, Self +from _typeshed import ReadableBuffer from abc import abstractmethod from collections.abc import Callable, Generator, Iterable from typing import Any, BinaryIO, Protocol, TextIO -from typing_extensions import Literal +from typing_extensions import Literal, Self __all__ = [ "register", @@ -110,7 +110,7 @@ class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]): def incrementaldecoder(self) -> _IncrementalDecoder: ... name: str def __new__( - cls: type[Self], + cls, encode: _Encoder, decode: _Decoder, streamreader: _StreamReader | None = None, @@ -210,7 +210,7 @@ class StreamWriter(Codec): def write(self, object: str) -> None: ... def writelines(self, list: Iterable[str]) -> None: ... def reset(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, type: type[BaseException] | None, value: BaseException | None, tb: types.TracebackType | None) -> None: ... def __getattr__(self, name: str, getattr: Callable[[str], Any] = ...) -> Any: ... @@ -222,9 +222,9 @@ class StreamReader(Codec): def readline(self, size: int | None = None, keepends: bool = True) -> str: ... def readlines(self, sizehint: int | None = None, keepends: bool = True) -> list[str]: ... def reset(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, type: type[BaseException] | None, value: BaseException | None, tb: types.TracebackType | None) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> str: ... def __getattr__(self, name: str, getattr: Callable[[str], Any] = ...) -> Any: ... @@ -237,12 +237,12 @@ class StreamReaderWriter(TextIO): def readline(self, size: int | None = None) -> str: ... def readlines(self, sizehint: int | None = None) -> list[str]: ... def __next__(self) -> str: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def write(self, data: str) -> None: ... # type: ignore[override] def writelines(self, list: Iterable[str]) -> None: ... def reset(self) -> None: ... def seek(self, offset: int, whence: int = 0) -> None: ... # type: ignore[override] - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, type: type[BaseException] | None, value: BaseException | None, tb: types.TracebackType | None) -> None: ... def __getattr__(self, name: str) -> Any: ... # These methods don't actually exist directly, but they are needed to satisfy the TextIO @@ -271,12 +271,12 @@ class StreamRecoder(BinaryIO): def readline(self, size: int | None = None) -> bytes: ... def readlines(self, sizehint: int | None = None) -> list[bytes]: ... def __next__(self) -> bytes: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def write(self, data: bytes) -> None: ... # type: ignore[override] def writelines(self, list: Iterable[bytes]) -> None: ... def reset(self) -> None: ... def __getattr__(self, name: str) -> Any: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, type: type[BaseException] | None, value: BaseException | None, tb: types.TracebackType | None) -> None: ... def seek(self, offset: int, whence: int = 0) -> None: ... # type: ignore[override] # These methods don't actually exist directly, but they are needed to satisfy the BinaryIO diff --git a/mypy/typeshed/stdlib/collections/__init__.pyi b/mypy/typeshed/stdlib/collections/__init__.pyi index d4c537b1384e..893a289d3cb1 100644 --- a/mypy/typeshed/stdlib/collections/__init__.pyi +++ b/mypy/typeshed/stdlib/collections/__init__.pyi @@ -1,8 +1,8 @@ import sys from _collections_abc import dict_items, dict_keys, dict_values -from _typeshed import Self, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT +from _typeshed import SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT from typing import Any, Generic, NoReturn, TypeVar, overload -from typing_extensions import SupportsIndex, final +from typing_extensions import Self, SupportsIndex, final if sys.version_info >= (3, 9): from types import GenericAlias @@ -68,8 +68,8 @@ class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __delitem__(self, key: _KT) -> None: ... def __iter__(self) -> Iterator[_KT]: ... def __contains__(self, key: object) -> bool: ... - def copy(self: Self) -> Self: ... - def __copy__(self: Self) -> Self: ... + def copy(self) -> Self: ... + def __copy__(self) -> Self: ... # `UserDict.fromkeys` has the same semantics as `dict.fromkeys`, so should be kept in line with `dict.fromkeys`. # TODO: Much like `dict.fromkeys`, the true signature of `UserDict.fromkeys` is inexpressible in the current type system. @@ -85,9 +85,9 @@ class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __ror__(self, other: UserDict[_T1, _T2] | dict[_T1, _T2]) -> UserDict[_KT | _T1, _VT | _T2]: ... # type: ignore[misc] # UserDict.__ior__ should be kept roughly in line with MutableMapping.update() @overload # type: ignore[misc] - def __ior__(self: Self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... + def __ior__(self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... @overload - def __ior__(self: Self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... + def __ior__(self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... class UserList(MutableSequence[_T]): data: list[_T] @@ -105,32 +105,32 @@ class UserList(MutableSequence[_T]): @overload def __getitem__(self, i: SupportsIndex) -> _T: ... @overload - def __getitem__(self: Self, i: slice) -> Self: ... + def __getitem__(self, i: slice) -> Self: ... @overload def __setitem__(self, i: SupportsIndex, item: _T) -> None: ... @overload def __setitem__(self, i: slice, item: Iterable[_T]) -> None: ... def __delitem__(self, i: SupportsIndex | slice) -> None: ... - def __add__(self: Self, other: Iterable[_T]) -> Self: ... - def __radd__(self: Self, other: Iterable[_T]) -> Self: ... - def __iadd__(self: Self, other: Iterable[_T]) -> Self: ... - def __mul__(self: Self, n: int) -> Self: ... - def __rmul__(self: Self, n: int) -> Self: ... - def __imul__(self: Self, n: int) -> Self: ... + def __add__(self, other: Iterable[_T]) -> Self: ... + def __radd__(self, other: Iterable[_T]) -> Self: ... + def __iadd__(self, other: Iterable[_T]) -> Self: ... + def __mul__(self, n: int) -> Self: ... + def __rmul__(self, n: int) -> Self: ... + def __imul__(self, n: int) -> Self: ... def append(self, item: _T) -> None: ... def insert(self, i: int, item: _T) -> None: ... def pop(self, i: int = -1) -> _T: ... def remove(self, item: _T) -> None: ... - def copy(self: Self) -> Self: ... - def __copy__(self: Self) -> Self: ... + def copy(self) -> Self: ... + def __copy__(self) -> Self: ... def count(self, item: _T) -> int: ... # All arguments are passed to `list.index` at runtime, so the signature should be kept in line with `list.index`. - def index(self, item: _T, __start: SupportsIndex = ..., __stop: SupportsIndex = ...) -> int: ... + def index(self, item: _T, __start: SupportsIndex = 0, __stop: SupportsIndex = sys.maxsize) -> int: ... # All arguments are passed to `list.sort` at runtime, so the signature should be kept in line with `list.sort`. @overload - def sort(self: UserList[SupportsRichComparisonT], *, key: None = ..., reverse: bool = ...) -> None: ... + def sort(self: UserList[SupportsRichComparisonT], *, key: None = None, reverse: bool = False) -> None: ... @overload - def sort(self, *, key: Callable[[_T], SupportsRichComparison], reverse: bool = ...) -> None: ... + def sort(self, *, key: Callable[[_T], SupportsRichComparison], reverse: bool = False) -> None: ... def extend(self, other: Iterable[_T]) -> None: ... class UserString(Sequence[UserString]): @@ -147,30 +147,30 @@ class UserString(Sequence[UserString]): def __eq__(self, string: object) -> bool: ... def __contains__(self, char: object) -> bool: ... def __len__(self) -> int: ... - def __getitem__(self: Self, index: SupportsIndex | slice) -> Self: ... - def __iter__(self: Self) -> Iterator[Self]: ... - def __reversed__(self: Self) -> Iterator[Self]: ... - def __add__(self: Self, other: object) -> Self: ... - def __radd__(self: Self, other: object) -> Self: ... - def __mul__(self: Self, n: int) -> Self: ... - def __rmul__(self: Self, n: int) -> Self: ... - def __mod__(self: Self, args: Any) -> Self: ... + def __getitem__(self, index: SupportsIndex | slice) -> Self: ... + def __iter__(self) -> Iterator[Self]: ... + def __reversed__(self) -> Iterator[Self]: ... + def __add__(self, other: object) -> Self: ... + def __radd__(self, other: object) -> Self: ... + def __mul__(self, n: int) -> Self: ... + def __rmul__(self, n: int) -> Self: ... + def __mod__(self, args: Any) -> Self: ... if sys.version_info >= (3, 8): - def __rmod__(self: Self, template: object) -> Self: ... + def __rmod__(self, template: object) -> Self: ... else: - def __rmod__(self: Self, format: Any) -> Self: ... + def __rmod__(self, format: Any) -> Self: ... - def capitalize(self: Self) -> Self: ... - def casefold(self: Self) -> Self: ... - def center(self: Self, width: int, *args: Any) -> Self: ... + def capitalize(self) -> Self: ... + def casefold(self) -> Self: ... + def center(self, width: int, *args: Any) -> Self: ... def count(self, sub: str | UserString, start: int = 0, end: int = sys.maxsize) -> int: ... if sys.version_info >= (3, 8): def encode(self: UserString, encoding: str | None = "utf-8", errors: str | None = "strict") -> bytes: ... else: - def encode(self: Self, encoding: str | None = None, errors: str | None = None) -> Self: ... + def encode(self, encoding: str | None = None, errors: str | None = None) -> Self: ... def endswith(self, suffix: str | tuple[str, ...], start: int | None = 0, end: int | None = sys.maxsize) -> bool: ... - def expandtabs(self: Self, tabsize: int = 8) -> Self: ... + def expandtabs(self, tabsize: int = 8) -> Self: ... def find(self, sub: str | UserString, start: int = 0, end: int = sys.maxsize) -> int: ... def format(self, *args: Any, **kwds: Any) -> str: ... def format_map(self, mapping: Mapping[str, Any]) -> str: ... @@ -188,63 +188,63 @@ class UserString(Sequence[UserString]): def isupper(self) -> bool: ... def isascii(self) -> bool: ... def join(self, seq: Iterable[str]) -> str: ... - def ljust(self: Self, width: int, *args: Any) -> Self: ... - def lower(self: Self) -> Self: ... - def lstrip(self: Self, chars: str | None = None) -> Self: ... + def ljust(self, width: int, *args: Any) -> Self: ... + def lower(self) -> Self: ... + def lstrip(self, chars: str | None = None) -> Self: ... maketrans = str.maketrans def partition(self, sep: str) -> tuple[str, str, str]: ... if sys.version_info >= (3, 9): - def removeprefix(self: Self, __prefix: str | UserString) -> Self: ... - def removesuffix(self: Self, __suffix: str | UserString) -> Self: ... + def removeprefix(self, __prefix: str | UserString) -> Self: ... + def removesuffix(self, __suffix: str | UserString) -> Self: ... - def replace(self: Self, old: str | UserString, new: str | UserString, maxsplit: int = -1) -> Self: ... + def replace(self, old: str | UserString, new: str | UserString, maxsplit: int = -1) -> Self: ... def rfind(self, sub: str | UserString, start: int = 0, end: int = sys.maxsize) -> int: ... def rindex(self, sub: str | UserString, start: int = 0, end: int = sys.maxsize) -> int: ... - def rjust(self: Self, width: int, *args: Any) -> Self: ... + def rjust(self, width: int, *args: Any) -> Self: ... def rpartition(self, sep: str) -> tuple[str, str, str]: ... - def rstrip(self: Self, chars: str | None = None) -> Self: ... + def rstrip(self, chars: str | None = None) -> Self: ... def split(self, sep: str | None = None, maxsplit: int = -1) -> list[str]: ... def rsplit(self, sep: str | None = None, maxsplit: int = -1) -> list[str]: ... def splitlines(self, keepends: bool = False) -> list[str]: ... def startswith(self, prefix: str | tuple[str, ...], start: int | None = 0, end: int | None = sys.maxsize) -> bool: ... - def strip(self: Self, chars: str | None = None) -> Self: ... - def swapcase(self: Self) -> Self: ... - def title(self: Self) -> Self: ... - def translate(self: Self, *args: Any) -> Self: ... - def upper(self: Self) -> Self: ... - def zfill(self: Self, width: int) -> Self: ... + def strip(self, chars: str | None = None) -> Self: ... + def swapcase(self) -> Self: ... + def title(self) -> Self: ... + def translate(self, *args: Any) -> Self: ... + def upper(self) -> Self: ... + def zfill(self, width: int) -> Self: ... class deque(MutableSequence[_T], Generic[_T]): @property def maxlen(self) -> int | None: ... @overload - def __init__(self, *, maxlen: int | None = ...) -> None: ... + def __init__(self, *, maxlen: int | None = None) -> None: ... @overload - def __init__(self, iterable: Iterable[_T], maxlen: int | None = ...) -> None: ... + def __init__(self, iterable: Iterable[_T], maxlen: int | None = None) -> None: ... def append(self, __x: _T) -> None: ... def appendleft(self, __x: _T) -> None: ... - def copy(self: Self) -> Self: ... + def copy(self) -> Self: ... def count(self, __x: _T) -> int: ... def extend(self, __iterable: Iterable[_T]) -> None: ... def extendleft(self, __iterable: Iterable[_T]) -> None: ... def insert(self, __i: int, __x: _T) -> None: ... - def index(self, __x: _T, __start: int = ..., __stop: int = ...) -> int: ... + def index(self, __x: _T, __start: int = 0, __stop: int = ...) -> int: ... def pop(self) -> _T: ... # type: ignore[override] def popleft(self) -> _T: ... def remove(self, __value: _T) -> None: ... - def rotate(self, __n: int = ...) -> None: ... - def __copy__(self: Self) -> Self: ... + def rotate(self, __n: int = 1) -> None: ... + def __copy__(self) -> Self: ... def __len__(self) -> int: ... # These methods of deque don't take slices, unlike MutableSequence, hence the type: ignores def __getitem__(self, __index: SupportsIndex) -> _T: ... # type: ignore[override] def __setitem__(self, __i: SupportsIndex, __x: _T) -> None: ... # type: ignore[override] def __delitem__(self, __i: SupportsIndex) -> None: ... # type: ignore[override] def __contains__(self, __o: object) -> bool: ... - def __reduce__(self: Self) -> tuple[type[Self], tuple[()], None, Iterator[_T]]: ... - def __iadd__(self: Self, __iterable: Iterable[_T]) -> Self: ... - def __add__(self: Self, __other: Self) -> Self: ... - def __mul__(self: Self, __other: int) -> Self: ... - def __imul__(self: Self, __other: int) -> Self: ... + def __reduce__(self) -> tuple[type[Self], tuple[()], None, Iterator[_T]]: ... + def __iadd__(self, __iterable: Iterable[_T]) -> Self: ... + def __add__(self, __other: Self) -> Self: ... + def __mul__(self, __other: int) -> Self: ... + def __imul__(self, __other: int) -> Self: ... def __lt__(self, __other: deque[_T]) -> bool: ... def __le__(self, __other: deque[_T]) -> bool: ... def __gt__(self, __other: deque[_T]) -> bool: ... @@ -261,7 +261,7 @@ class Counter(dict[_T, int], Generic[_T]): def __init__(self, __mapping: SupportsKeysAndGetItem[_T, int]) -> None: ... @overload def __init__(self, __iterable: Iterable[_T]) -> None: ... - def copy(self: Self) -> Self: ... + def copy(self) -> Self: ... def elements(self) -> Iterator[_T]: ... def most_common(self, n: int | None = None) -> list[tuple[_T, int]]: ... @classmethod @@ -281,9 +281,9 @@ class Counter(dict[_T, int], Generic[_T]): @overload # type: ignore[override] def update(self, __m: Mapping[_T, int], **kwargs: int) -> None: ... @overload - def update(self, __m: Iterable[_T], **kwargs: int) -> None: ... + def update(self, __iterable: Iterable[_T], **kwargs: int) -> None: ... @overload - def update(self, __m: None = ..., **kwargs: int) -> None: ... + def update(self, __iterable: None = None, **kwargs: int) -> None: ... def __missing__(self, key: _T) -> int: ... def __delitem__(self, elem: object) -> None: ... if sys.version_info >= (3, 10): @@ -297,10 +297,10 @@ class Counter(dict[_T, int], Generic[_T]): def __pos__(self) -> Counter[_T]: ... def __neg__(self) -> Counter[_T]: ... # several type: ignores because __iadd__ is supposedly incompatible with __add__, etc. - def __iadd__(self: Self, other: Counter[_T]) -> Self: ... # type: ignore[misc] - def __isub__(self: Self, other: Counter[_T]) -> Self: ... - def __iand__(self: Self, other: Counter[_T]) -> Self: ... - def __ior__(self: Self, other: Counter[_T]) -> Self: ... # type: ignore[override,misc] + def __iadd__(self, other: Counter[_T]) -> Self: ... # type: ignore[misc] + def __isub__(self, other: Counter[_T]) -> Self: ... + def __iand__(self, other: Counter[_T]) -> Self: ... + def __ior__(self, other: Counter[_T]) -> Self: ... # type: ignore[override,misc] if sys.version_info >= (3, 10): def total(self) -> int: ... def __le__(self, other: Counter[Any]) -> bool: ... @@ -338,7 +338,7 @@ class _odict_values(dict_values[_KT_co, _VT_co], Reversible[_VT_co], Generic[_KT class OrderedDict(dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]): def popitem(self, last: bool = True) -> tuple[_KT, _VT]: ... def move_to_end(self, key: _KT, last: bool = True) -> None: ... - def copy(self: Self) -> Self: ... + def copy(self) -> Self: ... def __reversed__(self) -> Iterator[_KT]: ... def keys(self) -> _odict_keys[_KT, _VT]: ... def items(self) -> _odict_items[_KT, _VT]: ... @@ -387,15 +387,15 @@ class defaultdict(dict[_KT, _VT], Generic[_KT, _VT]): **kwargs: _VT, ) -> None: ... def __missing__(self, __key: _KT) -> _VT: ... - def __copy__(self: Self) -> Self: ... - def copy(self: Self) -> Self: ... + def __copy__(self) -> Self: ... + def copy(self) -> Self: ... class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]): maps: list[MutableMapping[_KT, _VT]] def __init__(self, *maps: MutableMapping[_KT, _VT]) -> None: ... - def new_child(self: Self, m: MutableMapping[_KT, _VT] | None = None) -> Self: ... + def new_child(self, m: MutableMapping[_KT, _VT] | None = None) -> Self: ... @property - def parents(self: Self) -> Self: ... + def parents(self) -> Self: ... def __setitem__(self, key: _KT, value: _VT) -> None: ... def __delitem__(self, key: _KT) -> None: ... def __getitem__(self, key: _KT) -> _VT: ... @@ -412,13 +412,13 @@ class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]): @overload def pop(self, key: _KT) -> _VT: ... @overload - def pop(self, key: _KT, default: _VT | _T = ...) -> _VT | _T: ... - def copy(self: Self) -> Self: ... + def pop(self, key: _KT, default: _VT | _T) -> _VT | _T: ... + def copy(self) -> Self: ... __copy__ = copy # All arguments to `fromkeys` are passed to `dict.fromkeys` at runtime, so the signature should be kept in line with `dict.fromkeys`. @classmethod @overload - def fromkeys(cls, iterable: Iterable[_T], __value: None = ...) -> ChainMap[_T, Any | None]: ... + def fromkeys(cls, iterable: Iterable[_T], __value: None = None) -> ChainMap[_T, Any | None]: ... @classmethod @overload def fromkeys(cls, __iterable: Iterable[_T], __value: _S) -> ChainMap[_T, _S]: ... @@ -427,6 +427,6 @@ class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]): def __ror__(self, other: Mapping[_T1, _T2]) -> ChainMap[_KT | _T1, _VT | _T2]: ... # ChainMap.__ior__ should be kept roughly in line with MutableMapping.update() @overload # type: ignore[misc] - def __ior__(self: Self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... + def __ior__(self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... @overload - def __ior__(self: Self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... + def __ior__(self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... diff --git a/mypy/typeshed/stdlib/concurrent/futures/_base.pyi b/mypy/typeshed/stdlib/concurrent/futures/_base.pyi index 64084a884433..e792cf1a83c0 100644 --- a/mypy/typeshed/stdlib/concurrent/futures/_base.pyi +++ b/mypy/typeshed/stdlib/concurrent/futures/_base.pyi @@ -1,11 +1,11 @@ import sys import threading -from _typeshed import Self, Unused +from _typeshed import Unused from collections.abc import Callable, Iterable, Iterator, Sequence from logging import Logger from types import TracebackType from typing import Any, Generic, TypeVar, overload -from typing_extensions import Literal, ParamSpec, SupportsIndex +from typing_extensions import Literal, ParamSpec, Self, SupportsIndex if sys.version_info >= (3, 9): from types import GenericAlias @@ -62,7 +62,7 @@ class Executor: else: def shutdown(self, wait: bool = True) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> bool | None: ... diff --git a/mypy/typeshed/stdlib/contextlib.pyi b/mypy/typeshed/stdlib/contextlib.pyi index 522285abbc72..feb43aabb039 100644 --- a/mypy/typeshed/stdlib/contextlib.pyi +++ b/mypy/typeshed/stdlib/contextlib.pyi @@ -1,11 +1,11 @@ import abc import sys -from _typeshed import FileDescriptorOrPath, Self, Unused +from _typeshed import FileDescriptorOrPath, Unused from abc import abstractmethod from collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Generator, Iterator from types import TracebackType from typing import IO, Any, Generic, Protocol, TypeVar, overload, runtime_checkable -from typing_extensions import ParamSpec, TypeAlias +from typing_extensions import ParamSpec, Self, TypeAlias __all__ = [ "contextmanager", @@ -140,9 +140,9 @@ class ExitStack(metaclass=abc.ABCMeta): def enter_context(self, cm: AbstractContextManager[_T]) -> _T: ... def push(self, exit: _CM_EF) -> _CM_EF: ... def callback(self, __callback: Callable[_P, _T], *args: _P.args, **kwds: _P.kwargs) -> Callable[_P, _T]: ... - def pop_all(self: Self) -> Self: ... + def pop_all(self) -> Self: ... def close(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, __exc_type: type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None ) -> bool: ... @@ -163,9 +163,9 @@ class AsyncExitStack(metaclass=abc.ABCMeta): def push_async_callback( self, __callback: Callable[_P, Awaitable[_T]], *args: _P.args, **kwds: _P.kwargs ) -> Callable[_P, Awaitable[_T]]: ... - def pop_all(self: Self) -> Self: ... + def pop_all(self) -> Self: ... async def aclose(self) -> None: ... - async def __aenter__(self: Self) -> Self: ... + async def __aenter__(self) -> Self: ... async def __aexit__( self, __exc_type: type[BaseException] | None, __exc_value: BaseException | None, __traceback: TracebackType | None ) -> bool: ... diff --git a/mypy/typeshed/stdlib/copyreg.pyi b/mypy/typeshed/stdlib/copyreg.pyi index 07338b422385..8f7fd957fc52 100644 --- a/mypy/typeshed/stdlib/copyreg.pyi +++ b/mypy/typeshed/stdlib/copyreg.pyi @@ -1,9 +1,9 @@ from collections.abc import Callable, Hashable -from typing import Any, SupportsInt, TypeVar, Union +from typing import Any, SupportsInt, TypeVar from typing_extensions import TypeAlias _T = TypeVar("_T") -_Reduce: TypeAlias = Union[tuple[Callable[..., _T], tuple[Any, ...]], tuple[Callable[..., _T], tuple[Any, ...], Any | None]] +_Reduce: TypeAlias = tuple[Callable[..., _T], tuple[Any, ...]] | tuple[Callable[..., _T], tuple[Any, ...], Any | None] __all__ = ["pickle", "constructor", "add_extension", "remove_extension", "clear_extension_cache"] diff --git a/mypy/typeshed/stdlib/csv.pyi b/mypy/typeshed/stdlib/csv.pyi index 13b483b219d5..234b189fb3db 100644 --- a/mypy/typeshed/stdlib/csv.pyi +++ b/mypy/typeshed/stdlib/csv.pyi @@ -21,10 +21,10 @@ from _csv import ( unregister_dialect as unregister_dialect, writer as writer, ) -from _typeshed import Self, SupportsWrite +from _typeshed import SupportsWrite from collections.abc import Collection, Iterable, Iterator, Mapping, Sequence from typing import Any, Generic, TypeVar, overload -from typing_extensions import Literal +from typing_extensions import Literal, Self if sys.version_info >= (3, 8): from builtins import dict as _DictReadMapping @@ -107,7 +107,7 @@ class DictReader(Generic[_T], Iterator[_DictReadMapping[_T | Any, str | Any]]): quoting: _QuotingType = ..., strict: bool = ..., ) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _DictReadMapping[_T | Any, str | Any]: ... if sys.version_info >= (3, 12): def __class_getitem__(cls, item: Any) -> GenericAlias: ... diff --git a/mypy/typeshed/stdlib/ctypes/__init__.pyi b/mypy/typeshed/stdlib/ctypes/__init__.pyi index 5c4299989d92..497e2f7db70b 100644 --- a/mypy/typeshed/stdlib/ctypes/__init__.pyi +++ b/mypy/typeshed/stdlib/ctypes/__init__.pyi @@ -1,10 +1,10 @@ import sys from _ctypes import RTLD_GLOBAL as RTLD_GLOBAL, RTLD_LOCAL as RTLD_LOCAL -from _typeshed import ReadableBuffer, Self, WriteableBuffer +from _typeshed import ReadableBuffer, WriteableBuffer from abc import abstractmethod from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence -from typing import Any, ClassVar, Generic, TypeVar, Union as _UnionT, overload -from typing_extensions import TypeAlias +from typing import Any, ClassVar, Generic, TypeVar, overload +from typing_extensions import Self, TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias @@ -77,21 +77,21 @@ class _CData(metaclass=_CDataMeta): _b_needsfree_: bool _objects: Mapping[Any, int] | None @classmethod - def from_buffer(cls: type[Self], source: WriteableBuffer, offset: int = ...) -> Self: ... + def from_buffer(cls, source: WriteableBuffer, offset: int = ...) -> Self: ... @classmethod - def from_buffer_copy(cls: type[Self], source: ReadableBuffer, offset: int = ...) -> Self: ... + def from_buffer_copy(cls, source: ReadableBuffer, offset: int = ...) -> Self: ... @classmethod - def from_address(cls: type[Self], address: int) -> Self: ... + def from_address(cls, address: int) -> Self: ... @classmethod - def from_param(cls: type[Self], obj: Any) -> Self | _CArgObject: ... + def from_param(cls, obj: Any) -> Self | _CArgObject: ... @classmethod - def in_dll(cls: type[Self], library: CDLL, name: str) -> Self: ... + def in_dll(cls, library: CDLL, name: str) -> Self: ... class _CanCastTo(_CData): ... class _PointerLike(_CanCastTo): ... _ECT: TypeAlias = Callable[[type[_CData] | None, _FuncPointer, tuple[_CData, ...]], _CData] -_PF: TypeAlias = _UnionT[tuple[int], tuple[int, str], tuple[int, str, Any]] +_PF: TypeAlias = tuple[int] | tuple[int, str] | tuple[int, str, Any] class _FuncPointer(_PointerLike, _CData): restype: type[_CData] | Callable[[int], Any] | None diff --git a/mypy/typeshed/stdlib/dataclasses.pyi b/mypy/typeshed/stdlib/dataclasses.pyi index 3b7327137ec5..c02aaabe6196 100644 --- a/mypy/typeshed/stdlib/dataclasses.pyi +++ b/mypy/typeshed/stdlib/dataclasses.pyi @@ -1,9 +1,10 @@ import enum import sys import types +from _typeshed import DataclassInstance from builtins import type as Type # alias to avoid name clashes with fields named "type" from collections.abc import Callable, Iterable, Mapping -from typing import Any, ClassVar, Generic, Protocol, TypeVar, overload +from typing import Any, Generic, Protocol, TypeVar, overload from typing_extensions import Literal, TypeAlias, TypeGuard if sys.version_info >= (3, 9): @@ -30,10 +31,7 @@ __all__ = [ if sys.version_info >= (3, 10): __all__ += ["KW_ONLY"] -class _DataclassInstance(Protocol): - __dataclass_fields__: ClassVar[dict[str, Field[Any]]] - -_DataclassT = TypeVar("_DataclassT", bound=_DataclassInstance) +_DataclassT = TypeVar("_DataclassT", bound=DataclassInstance) # define _MISSING_TYPE as an enum within the type stubs, # even though that is not really its type at runtime @@ -49,26 +47,26 @@ if sys.version_info >= (3, 10): class KW_ONLY: ... @overload -def asdict(obj: _DataclassInstance) -> dict[str, Any]: ... +def asdict(obj: DataclassInstance) -> dict[str, Any]: ... @overload -def asdict(obj: _DataclassInstance, *, dict_factory: Callable[[list[tuple[str, Any]]], _T]) -> _T: ... +def asdict(obj: DataclassInstance, *, dict_factory: Callable[[list[tuple[str, Any]]], _T]) -> _T: ... @overload -def astuple(obj: _DataclassInstance) -> tuple[Any, ...]: ... +def astuple(obj: DataclassInstance) -> tuple[Any, ...]: ... @overload -def astuple(obj: _DataclassInstance, *, tuple_factory: Callable[[list[Any]], _T]) -> _T: ... +def astuple(obj: DataclassInstance, *, tuple_factory: Callable[[list[Any]], _T]) -> _T: ... if sys.version_info >= (3, 8): # cls argument is now positional-only @overload - def dataclass(__cls: type[_T]) -> type[_T]: ... - @overload def dataclass(__cls: None) -> Callable[[type[_T]], type[_T]]: ... + @overload + def dataclass(__cls: type[_T]) -> type[_T]: ... else: - @overload - def dataclass(_cls: type[_T]) -> type[_T]: ... @overload def dataclass(_cls: None) -> Callable[[type[_T]], type[_T]]: ... + @overload + def dataclass(_cls: type[_T]) -> type[_T]: ... if sys.version_info >= (3, 11): @overload @@ -223,13 +221,13 @@ else: metadata: Mapping[Any, Any] | None = None, ) -> Any: ... -def fields(class_or_instance: _DataclassInstance | type[_DataclassInstance]) -> tuple[Field[Any], ...]: ... +def fields(class_or_instance: DataclassInstance | type[DataclassInstance]) -> tuple[Field[Any], ...]: ... @overload -def is_dataclass(obj: _DataclassInstance | type[_DataclassInstance]) -> Literal[True]: ... +def is_dataclass(obj: DataclassInstance | type[DataclassInstance]) -> Literal[True]: ... @overload -def is_dataclass(obj: type) -> TypeGuard[type[_DataclassInstance]]: ... +def is_dataclass(obj: type) -> TypeGuard[type[DataclassInstance]]: ... @overload -def is_dataclass(obj: object) -> TypeGuard[_DataclassInstance | type[_DataclassInstance]]: ... +def is_dataclass(obj: object) -> TypeGuard[DataclassInstance | type[DataclassInstance]]: ... class FrozenInstanceError(AttributeError): ... diff --git a/mypy/typeshed/stdlib/datetime.pyi b/mypy/typeshed/stdlib/datetime.pyi index 377ef0067485..4da5501ce76d 100644 --- a/mypy/typeshed/stdlib/datetime.pyi +++ b/mypy/typeshed/stdlib/datetime.pyi @@ -1,9 +1,8 @@ import sys -from _typeshed import Self from abc import abstractmethod from time import struct_time from typing import ClassVar, NamedTuple, NoReturn, TypeVar, overload -from typing_extensions import Literal, TypeAlias, final +from typing_extensions import Literal, Self, TypeAlias, final if sys.version_info >= (3, 11): __all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo", "MINYEAR", "MAXYEAR", "UTC") @@ -50,18 +49,18 @@ class date: min: ClassVar[date] max: ClassVar[date] resolution: ClassVar[timedelta] - def __new__(cls: type[Self], year: int, month: int, day: int) -> Self: ... + def __new__(cls, year: int, month: int, day: int) -> Self: ... @classmethod - def fromtimestamp(cls: type[Self], __timestamp: float) -> Self: ... + def fromtimestamp(cls, __timestamp: float) -> Self: ... @classmethod - def today(cls: type[Self]) -> Self: ... + def today(cls) -> Self: ... @classmethod - def fromordinal(cls: type[Self], __n: int) -> Self: ... + def fromordinal(cls, __n: int) -> Self: ... @classmethod - def fromisoformat(cls: type[Self], __date_string: str) -> Self: ... + def fromisoformat(cls, __date_string: str) -> Self: ... if sys.version_info >= (3, 8): @classmethod - def fromisocalendar(cls: type[Self], year: int, week: int, day: int) -> Self: ... + def fromisocalendar(cls, year: int, week: int, day: int) -> Self: ... @property def year(self) -> int: ... @@ -82,16 +81,16 @@ class date: def isoformat(self) -> str: ... def timetuple(self) -> struct_time: ... def toordinal(self) -> int: ... - def replace(self: Self, year: int = ..., month: int = ..., day: int = ...) -> Self: ... + def replace(self, year: int = ..., month: int = ..., day: int = ...) -> Self: ... def __le__(self, __other: date) -> bool: ... def __lt__(self, __other: date) -> bool: ... def __ge__(self, __other: date) -> bool: ... def __gt__(self, __other: date) -> bool: ... if sys.version_info >= (3, 8): - def __add__(self: Self, __other: timedelta) -> Self: ... - def __radd__(self: Self, __other: timedelta) -> Self: ... + def __add__(self, __other: timedelta) -> Self: ... + def __radd__(self, __other: timedelta) -> Self: ... @overload - def __sub__(self: Self, __other: timedelta) -> Self: ... + def __sub__(self, __other: timedelta) -> Self: ... @overload def __sub__(self, __other: datetime) -> NoReturn: ... @overload @@ -119,7 +118,7 @@ class time: max: ClassVar[time] resolution: ClassVar[timedelta] def __new__( - cls: type[Self], + cls, hour: int = ..., minute: int = ..., second: int = ..., @@ -146,7 +145,7 @@ class time: def __gt__(self, __other: time) -> bool: ... def isoformat(self, timespec: str = ...) -> str: ... @classmethod - def fromisoformat(cls: type[Self], __time_string: str) -> Self: ... + def fromisoformat(cls, __time_string: str) -> Self: ... # On <3.12, the name of the parameter in the pure-Python implementation # didn't match the name in the C implementation, # meaning it is only *safe* to pass it as a keyword argument on 3.12+ @@ -160,7 +159,7 @@ class time: def tzname(self) -> str | None: ... def dst(self) -> timedelta | None: ... def replace( - self: Self, + self, hour: int = ..., minute: int = ..., second: int = ..., @@ -178,7 +177,7 @@ class timedelta: max: ClassVar[timedelta] resolution: ClassVar[timedelta] def __new__( - cls: type[Self], + cls, days: float = ..., seconds: float = ..., microseconds: float = ..., @@ -223,7 +222,7 @@ class datetime(date): min: ClassVar[datetime] max: ClassVar[datetime] def __new__( - cls: type[Self], + cls, year: int, month: int, day: int, @@ -252,35 +251,35 @@ class datetime(date): # meaning it is only *safe* to pass it as a keyword argument on 3.12+ if sys.version_info >= (3, 12): @classmethod - def fromtimestamp(cls: type[Self], timestamp: float, tz: _TzInfo | None = ...) -> Self: ... + def fromtimestamp(cls, timestamp: float, tz: _TzInfo | None = ...) -> Self: ... else: @classmethod - def fromtimestamp(cls: type[Self], __timestamp: float, tz: _TzInfo | None = ...) -> Self: ... + def fromtimestamp(cls, __timestamp: float, tz: _TzInfo | None = ...) -> Self: ... @classmethod - def utcfromtimestamp(cls: type[Self], __t: float) -> Self: ... + def utcfromtimestamp(cls, __t: float) -> Self: ... if sys.version_info >= (3, 8): @classmethod - def now(cls: type[Self], tz: _TzInfo | None = None) -> Self: ... + def now(cls, tz: _TzInfo | None = None) -> Self: ... else: @overload @classmethod - def now(cls: type[Self], tz: None = None) -> Self: ... + def now(cls, tz: None = None) -> Self: ... @overload @classmethod def now(cls, tz: _TzInfo) -> datetime: ... @classmethod - def utcnow(cls: type[Self]) -> Self: ... + def utcnow(cls) -> Self: ... @classmethod - def combine(cls, date: _Date, time: _Time, tzinfo: _TzInfo | None = ...) -> datetime: ... + def combine(cls, date: _Date, time: _Time, tzinfo: _TzInfo | None = ...) -> Self: ... def timestamp(self) -> float: ... def utctimetuple(self) -> struct_time: ... def date(self) -> _Date: ... def time(self) -> _Time: ... def timetz(self) -> _Time: ... def replace( - self: Self, + self, year: int = ..., month: int = ..., day: int = ..., @@ -293,13 +292,13 @@ class datetime(date): fold: int = ..., ) -> Self: ... if sys.version_info >= (3, 8): - def astimezone(self: Self, tz: _TzInfo | None = ...) -> Self: ... + def astimezone(self, tz: _TzInfo | None = ...) -> Self: ... else: def astimezone(self, tz: _TzInfo | None = ...) -> datetime: ... def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ... @classmethod - def strptime(cls, __date_string: str, __format: str) -> datetime: ... + def strptime(cls, __date_string: str, __format: str) -> Self: ... def utcoffset(self) -> timedelta | None: ... def tzname(self) -> str | None: ... def dst(self) -> timedelta | None: ... @@ -309,7 +308,7 @@ class datetime(date): def __gt__(self, __other: datetime) -> bool: ... # type: ignore[override] if sys.version_info >= (3, 8): @overload # type: ignore[override] - def __sub__(self: Self, __other: timedelta) -> Self: ... + def __sub__(self, __other: timedelta) -> Self: ... @overload def __sub__(self: _D, __other: _D) -> timedelta: ... else: diff --git a/mypy/typeshed/stdlib/dbm/__init__.pyi b/mypy/typeshed/stdlib/dbm/__init__.pyi index ab224086b7be..0068d67b6ad1 100644 --- a/mypy/typeshed/stdlib/dbm/__init__.pyi +++ b/mypy/typeshed/stdlib/dbm/__init__.pyi @@ -1,7 +1,6 @@ -from _typeshed import Self from collections.abc import Iterator, MutableMapping from types import TracebackType -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias __all__ = ["open", "whichdb", "error"] @@ -82,7 +81,7 @@ class _Database(MutableMapping[_KeyType, bytes]): def __iter__(self) -> Iterator[bytes]: ... def __len__(self) -> int: ... def __del__(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/dbm/dumb.pyi b/mypy/typeshed/stdlib/dbm/dumb.pyi index d65d163ab568..1fc68cf71f9d 100644 --- a/mypy/typeshed/stdlib/dbm/dumb.pyi +++ b/mypy/typeshed/stdlib/dbm/dumb.pyi @@ -1,7 +1,6 @@ -from _typeshed import Self from collections.abc import Iterator, MutableMapping from types import TracebackType -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias __all__ = ["error", "open"] @@ -24,7 +23,7 @@ class _Database(MutableMapping[_KeyType, bytes]): def __iter__(self) -> Iterator[bytes]: ... def __len__(self) -> int: ... def __del__(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/dbm/gnu.pyi b/mypy/typeshed/stdlib/dbm/gnu.pyi index adaf6fa8e69b..3dc66a30c370 100644 --- a/mypy/typeshed/stdlib/dbm/gnu.pyi +++ b/mypy/typeshed/stdlib/dbm/gnu.pyi @@ -1,8 +1,8 @@ import sys -from _typeshed import ReadOnlyBuffer, Self +from _typeshed import ReadOnlyBuffer from types import TracebackType from typing import TypeVar, overload -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias if sys.platform != "win32": _T = TypeVar("_T") @@ -24,7 +24,7 @@ if sys.platform != "win32": def __delitem__(self, key: _KeyType) -> None: ... def __contains__(self, key: _KeyType) -> bool: ... def __len__(self) -> int: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/dbm/ndbm.pyi b/mypy/typeshed/stdlib/dbm/ndbm.pyi index ac0b75dfa45b..1106fb2a8e7e 100644 --- a/mypy/typeshed/stdlib/dbm/ndbm.pyi +++ b/mypy/typeshed/stdlib/dbm/ndbm.pyi @@ -1,8 +1,8 @@ import sys -from _typeshed import ReadOnlyBuffer, Self +from _typeshed import ReadOnlyBuffer from types import TracebackType from typing import TypeVar, overload -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias if sys.platform != "win32": _T = TypeVar("_T") @@ -20,7 +20,7 @@ if sys.platform != "win32": def __delitem__(self, key: _KeyType) -> None: ... def __len__(self) -> int: ... def __del__(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/dis.pyi b/mypy/typeshed/stdlib/dis.pyi index ea837f09c806..ac0c5356f5f9 100644 --- a/mypy/typeshed/stdlib/dis.pyi +++ b/mypy/typeshed/stdlib/dis.pyi @@ -1,10 +1,9 @@ import sys import types -from _typeshed import Self from collections.abc import Callable, Iterator from opcode import * # `dis` re-exports it as a part of public API from typing import IO, Any, NamedTuple -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias __all__ = [ "code_info", @@ -82,15 +81,13 @@ class Bytecode: adaptive: bool = False, ) -> None: ... @classmethod - def from_traceback( - cls: type[Self], tb: types.TracebackType, *, show_caches: bool = False, adaptive: bool = False - ) -> Self: ... + def from_traceback(cls, tb: types.TracebackType, *, show_caches: bool = False, adaptive: bool = False) -> Self: ... else: def __init__( self, x: _HaveCodeType | str, *, first_line: int | None = None, current_offset: int | None = None ) -> None: ... @classmethod - def from_traceback(cls: type[Self], tb: types.TracebackType) -> Self: ... + def from_traceback(cls, tb: types.TracebackType) -> Self: ... def __iter__(self) -> Iterator[Instruction]: ... def info(self) -> str: ... diff --git a/mypy/typeshed/stdlib/distutils/ccompiler.pyi b/mypy/typeshed/stdlib/distutils/ccompiler.pyi index 711b30ba4e0e..e7277aa3f9c4 100644 --- a/mypy/typeshed/stdlib/distutils/ccompiler.pyi +++ b/mypy/typeshed/stdlib/distutils/ccompiler.pyi @@ -1,8 +1,8 @@ from collections.abc import Callable -from typing import Any, Union +from typing import Any from typing_extensions import TypeAlias -_Macro: TypeAlias = Union[tuple[str], tuple[str, str | None]] +_Macro: TypeAlias = tuple[str] | tuple[str, str | None] def gen_lib_options( compiler: CCompiler, library_dirs: list[str], runtime_library_dirs: list[str], libraries: list[str] diff --git a/mypy/typeshed/stdlib/distutils/command/check.pyi b/mypy/typeshed/stdlib/distutils/command/check.pyi index cdbe40fff71d..9cbcc6c87f21 100644 --- a/mypy/typeshed/stdlib/distutils/command/check.pyi +++ b/mypy/typeshed/stdlib/distutils/command/check.pyi @@ -6,6 +6,8 @@ from ..cmd import Command _Reporter: TypeAlias = Any # really docutils.utils.Reporter # Only defined if docutils is installed. +# Depends on a third-party stub. Since distutils is deprecated anyway, +# it's easier to just suppress the "any subclassing" error. class SilentReporter(_Reporter): messages: Any def __init__( diff --git a/mypy/typeshed/stdlib/distutils/version.pyi b/mypy/typeshed/stdlib/distutils/version.pyi index 4f1b64a7381d..47da65ef87aa 100644 --- a/mypy/typeshed/stdlib/distutils/version.pyi +++ b/mypy/typeshed/stdlib/distutils/version.pyi @@ -1,36 +1,36 @@ -from _typeshed import Self from abc import abstractmethod from re import Pattern +from typing_extensions import Self class Version: def __eq__(self, other: object) -> bool: ... - def __lt__(self: Self, other: Self | str) -> bool: ... - def __le__(self: Self, other: Self | str) -> bool: ... - def __gt__(self: Self, other: Self | str) -> bool: ... - def __ge__(self: Self, other: Self | str) -> bool: ... + def __lt__(self, other: Self | str) -> bool: ... + def __le__(self, other: Self | str) -> bool: ... + def __gt__(self, other: Self | str) -> bool: ... + def __ge__(self, other: Self | str) -> bool: ... @abstractmethod def __init__(self, vstring: str | None = None) -> None: ... @abstractmethod - def parse(self: Self, vstring: str) -> Self: ... + def parse(self, vstring: str) -> Self: ... @abstractmethod def __str__(self) -> str: ... @abstractmethod - def _cmp(self: Self, other: Self | str) -> bool: ... + def _cmp(self, other: Self | str) -> bool: ... class StrictVersion(Version): version_re: Pattern[str] version: tuple[int, int, int] prerelease: tuple[str, int] | None def __init__(self, vstring: str | None = None) -> None: ... - def parse(self: Self, vstring: str) -> Self: ... + def parse(self, vstring: str) -> Self: ... def __str__(self) -> str: ... # noqa: Y029 - def _cmp(self: Self, other: Self | str) -> bool: ... + def _cmp(self, other: Self | str) -> bool: ... class LooseVersion(Version): component_re: Pattern[str] vstring: str version: tuple[str | int, ...] def __init__(self, vstring: str | None = None) -> None: ... - def parse(self: Self, vstring: str) -> Self: ... + def parse(self, vstring: str) -> Self: ... def __str__(self) -> str: ... # noqa: Y029 - def _cmp(self: Self, other: Self | str) -> bool: ... + def _cmp(self, other: Self | str) -> bool: ... diff --git a/mypy/typeshed/stdlib/email/__init__.pyi b/mypy/typeshed/stdlib/email/__init__.pyi index 6b59dc73d5cc..fca302f5f1a7 100644 --- a/mypy/typeshed/stdlib/email/__init__.pyi +++ b/mypy/typeshed/stdlib/email/__init__.pyi @@ -1,12 +1,12 @@ from collections.abc import Callable from email.message import Message from email.policy import Policy -from typing import IO, Union +from typing import IO from typing_extensions import TypeAlias # Definitions imported by multiple submodules in typeshed -_ParamType: TypeAlias = Union[str, tuple[str | None, str | None, str]] # noqa: Y047 -_ParamsType: TypeAlias = Union[str, None, tuple[str, str | None, str]] # noqa: Y047 +_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: ... diff --git a/mypy/typeshed/stdlib/email/_header_value_parser.pyi b/mypy/typeshed/stdlib/email/_header_value_parser.pyi index 0e422294e77a..97008140ec5d 100644 --- a/mypy/typeshed/stdlib/email/_header_value_parser.pyi +++ b/mypy/typeshed/stdlib/email/_header_value_parser.pyi @@ -1,11 +1,10 @@ import sys -from _typeshed import Self from collections.abc import Iterable, Iterator from email.errors import HeaderParseError, MessageDefect from email.policy import Policy from re import Pattern from typing import Any -from typing_extensions import Final +from typing_extensions import Final, Self WSP: Final[set[str]] CFWS_LEADER: Final[set[str]] @@ -318,7 +317,7 @@ class Terminal(str): syntactic_break: bool token_type: str defects: list[MessageDefect] - def __new__(cls: type[Self], value: str, token_type: str) -> Self: ... + def __new__(cls, value: str, token_type: str) -> Self: ... def pprint(self) -> None: ... @property def all_defects(self) -> list[MessageDefect]: ... diff --git a/mypy/typeshed/stdlib/email/headerregistry.pyi b/mypy/typeshed/stdlib/email/headerregistry.pyi index df07e2458e81..e158e89818f7 100644 --- a/mypy/typeshed/stdlib/email/headerregistry.pyi +++ b/mypy/typeshed/stdlib/email/headerregistry.pyi @@ -1,6 +1,5 @@ import sys import types -from _typeshed import Self from collections.abc import Iterable, Mapping from datetime import datetime as _datetime from email._header_value_parser import ( @@ -15,7 +14,7 @@ from email._header_value_parser import ( from email.errors import MessageDefect from email.policy import Policy from typing import Any, ClassVar, Protocol -from typing_extensions import Literal +from typing_extensions import Literal, Self class BaseHeader(str): # max_count is actually more of an abstract ClassVar (not defined on the base class, but expected to be defined in subclasses) @@ -24,7 +23,7 @@ class BaseHeader(str): def name(self) -> str: ... @property def defects(self) -> tuple[MessageDefect, ...]: ... - def __new__(cls: type[Self], name: str, value: Any) -> Self: ... + def __new__(cls, name: str, value: Any) -> Self: ... def init(self, name: str, *, parse_tree: TokenList, defects: Iterable[MessageDefect]) -> None: ... def fold(self, *, policy: Policy) -> str: ... diff --git a/mypy/typeshed/stdlib/email/message.pyi b/mypy/typeshed/stdlib/email/message.pyi index 2777450a77ba..14e018073103 100644 --- a/mypy/typeshed/stdlib/email/message.pyi +++ b/mypy/typeshed/stdlib/email/message.pyi @@ -1,4 +1,3 @@ -from _typeshed import Self from collections.abc import Generator, Iterator, Sequence from email import _ParamsType, _ParamType from email.charset import Charset @@ -6,7 +5,7 @@ from email.contentmanager import ContentManager from email.errors import MessageDefect from email.policy import Policy from typing import Any, TypeVar, overload -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias __all__ = ["Message", "EmailMessage"] @@ -84,7 +83,7 @@ class Message: def get_charsets(self, failobj: None = None) -> list[str] | None: ... @overload def get_charsets(self, failobj: _T) -> list[str] | _T: ... - def walk(self: Self) -> Generator[Self, None, None]: ... + def walk(self) -> Generator[Self, None, None]: ... def get_content_disposition(self) -> str | None: ... def as_string(self, unixfrom: bool = False, maxheaderlen: int = 0, policy: Policy | None = None) -> str: ... def as_bytes(self, unixfrom: bool = False, policy: Policy | None = None) -> bytes: ... diff --git a/mypy/typeshed/stdlib/email/parser.pyi b/mypy/typeshed/stdlib/email/parser.pyi index ba5dace28916..28b6aca856ca 100644 --- a/mypy/typeshed/stdlib/email/parser.pyi +++ b/mypy/typeshed/stdlib/email/parser.pyi @@ -1,25 +1,26 @@ +from _typeshed import SupportsRead from collections.abc import Callable from email.feedparser import BytesFeedParser as BytesFeedParser, FeedParser as FeedParser from email.message import Message from email.policy import Policy -from typing import BinaryIO, TextIO +from typing import IO __all__ = ["Parser", "HeaderParser", "BytesParser", "BytesHeaderParser", "FeedParser", "BytesFeedParser"] class Parser: def __init__(self, _class: Callable[[], Message] | None = None, *, policy: Policy = ...) -> None: ... - def parse(self, fp: TextIO, headersonly: bool = False) -> Message: ... + def parse(self, fp: SupportsRead[str], headersonly: bool = False) -> Message: ... def parsestr(self, text: str, headersonly: bool = False) -> Message: ... class HeaderParser(Parser): - def parse(self, fp: TextIO, headersonly: bool = True) -> Message: ... + def parse(self, fp: SupportsRead[str], headersonly: bool = True) -> Message: ... def parsestr(self, text: str, headersonly: bool = True) -> Message: ... class BytesParser: def __init__(self, _class: Callable[[], Message] = ..., *, policy: Policy = ...) -> None: ... - def parse(self, fp: BinaryIO, headersonly: bool = False) -> Message: ... + def parse(self, fp: IO[bytes], headersonly: bool = False) -> Message: ... def parsebytes(self, text: bytes | bytearray, headersonly: bool = False) -> Message: ... class BytesHeaderParser(BytesParser): - def parse(self, fp: BinaryIO, headersonly: bool = True) -> Message: ... + def parse(self, fp: IO[bytes], headersonly: bool = True) -> Message: ... def parsebytes(self, text: bytes | bytearray, headersonly: bool = True) -> Message: ... diff --git a/mypy/typeshed/stdlib/enum.pyi b/mypy/typeshed/stdlib/enum.pyi index 182076731ab2..b46fe429cacb 100644 --- a/mypy/typeshed/stdlib/enum.pyi +++ b/mypy/typeshed/stdlib/enum.pyi @@ -1,11 +1,12 @@ +import _typeshed import sys import types -from _typeshed import Self, SupportsKeysAndGetItem, Unused +from _typeshed import SupportsKeysAndGetItem, Unused from abc import ABCMeta from builtins import property as _builtins_property from collections.abc import Iterable, Iterator, Mapping from typing import Any, Generic, TypeVar, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias __all__ = ["EnumMeta", "Enum", "IntEnum", "Flag", "IntFlag", "auto", "unique"] @@ -80,7 +81,7 @@ class _EnumDict(dict[str, Any]): class EnumMeta(ABCMeta): if sys.version_info >= (3, 11): def __new__( - metacls: type[Self], + metacls: type[_typeshed.Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict, @@ -88,11 +89,13 @@ class EnumMeta(ABCMeta): boundary: FlagBoundary | None = None, _simple: bool = False, **kwds: Any, - ) -> Self: ... + ) -> _typeshed.Self: ... elif sys.version_info >= (3, 9): - def __new__(metacls: type[Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict, **kwds: Any) -> Self: ... + def __new__( + metacls: type[_typeshed.Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict, **kwds: Any + ) -> _typeshed.Self: ... else: - def __new__(metacls: type[Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict) -> Self: ... + def __new__(metacls: type[_typeshed.Self], cls: str, bases: tuple[type, ...], classdict: _EnumDict) -> _typeshed.Self: ... if sys.version_info >= (3, 9): @classmethod @@ -174,7 +177,7 @@ class Enum(metaclass=EnumMeta): # However, using `Any` causes too many false-positives for those using mypy's `--disallow-any-expr` # (see #7752, #2539, mypy/#5788), # and in practice using `object` here has the same effect as using `Any`. - def __new__(cls: type[Self], value: object) -> Self: ... + def __new__(cls, value: object) -> Self: ... def __dir__(self) -> list[str]: ... def __format__(self, format_spec: str) -> str: ... def __reduce_ex__(self, proto: Unused) -> tuple[Any, ...]: ... @@ -191,7 +194,7 @@ class IntEnum(int, _IntEnumBase): _value_: int @_magic_enum_attr def value(self) -> int: ... - def __new__(cls: type[Self], value: int) -> Self: ... + def __new__(cls, value: int) -> Self: ... def unique(enumeration: _EnumerationT) -> _EnumerationT: ... @@ -202,7 +205,7 @@ class auto(IntFlag): _value_: Any @_magic_enum_attr def value(self) -> Any: ... - def __new__(cls: type[Self]) -> Self: ... + def __new__(cls) -> Self: ... class Flag(Enum): _name_: str | None # type: ignore[assignment] @@ -211,14 +214,14 @@ class Flag(Enum): def name(self) -> str | None: ... # type: ignore[override] @_magic_enum_attr def value(self) -> int: ... - def __contains__(self: Self, other: Self) -> bool: ... + def __contains__(self, other: Self) -> bool: ... def __bool__(self) -> bool: ... - def __or__(self: Self, other: Self) -> Self: ... - def __and__(self: Self, other: Self) -> Self: ... - def __xor__(self: Self, other: Self) -> Self: ... - def __invert__(self: Self) -> Self: ... + def __or__(self, other: Self) -> Self: ... + def __and__(self, other: Self) -> Self: ... + def __xor__(self, other: Self) -> Self: ... + def __invert__(self) -> Self: ... if sys.version_info >= (3, 11): - def __iter__(self: Self) -> Iterator[Self]: ... + def __iter__(self) -> Iterator[Self]: ... def __len__(self) -> int: ... __ror__ = __or__ __rand__ = __and__ @@ -226,28 +229,28 @@ class Flag(Enum): if sys.version_info >= (3, 11): # The body of the class is the same, but the base classes are different. - class IntFlag(int, ReprEnum, Flag, boundary=KEEP): - def __new__(cls: type[Self], value: int) -> Self: ... - def __or__(self: Self, other: int) -> Self: ... - def __and__(self: Self, other: int) -> Self: ... - def __xor__(self: Self, other: int) -> Self: ... + class IntFlag(int, ReprEnum, Flag, boundary=KEEP): # type: ignore[misc] # complaints about incompatible bases + def __new__(cls, value: int) -> Self: ... + def __or__(self, other: int) -> Self: ... + def __and__(self, other: int) -> Self: ... + def __xor__(self, other: int) -> Self: ... __ror__ = __or__ __rand__ = __and__ __rxor__ = __xor__ else: - class IntFlag(int, Flag): - def __new__(cls: type[Self], value: int) -> Self: ... - def __or__(self: Self, other: int) -> Self: ... - def __and__(self: Self, other: int) -> Self: ... - def __xor__(self: Self, other: int) -> Self: ... + class IntFlag(int, Flag): # type: ignore[misc] # complaints about incompatible bases + def __new__(cls, value: int) -> Self: ... + def __or__(self, other: int) -> Self: ... + def __and__(self, other: int) -> Self: ... + def __xor__(self, other: int) -> Self: ... __ror__ = __or__ __rand__ = __and__ __rxor__ = __xor__ if sys.version_info >= (3, 11): class StrEnum(str, ReprEnum): - def __new__(cls: type[Self], value: str) -> Self: ... + def __new__(cls, value: str) -> Self: ... _value_: str @_magic_enum_attr def value(self) -> str: ... diff --git a/mypy/typeshed/stdlib/fileinput.pyi b/mypy/typeshed/stdlib/fileinput.pyi index 17379e92ba5f..e9f3713b4eaf 100644 --- a/mypy/typeshed/stdlib/fileinput.pyi +++ b/mypy/typeshed/stdlib/fileinput.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import AnyStr_co, Self, StrOrBytesPath +from _typeshed import AnyStr_co, StrOrBytesPath from collections.abc import Callable, Iterable, Iterator from types import TracebackType from typing import IO, Any, AnyStr, Generic, Protocol, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias @@ -289,11 +289,11 @@ class FileInput(Iterator[AnyStr], Generic[AnyStr]): def __del__(self) -> None: ... def close(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> AnyStr: ... if sys.version_info < (3, 11): def __getitem__(self, i: int) -> AnyStr: ... diff --git a/mypy/typeshed/stdlib/fractions.pyi b/mypy/typeshed/stdlib/fractions.pyi index 95e4aad0f9ca..97cefc916d9b 100644 --- a/mypy/typeshed/stdlib/fractions.pyi +++ b/mypy/typeshed/stdlib/fractions.pyi @@ -1,10 +1,9 @@ import sys -from _typeshed import Self from collections.abc import Callable from decimal import Decimal from numbers import Integral, Rational, Real from typing import Any, overload -from typing_extensions import Literal, SupportsIndex, TypeAlias +from typing_extensions import Literal, Self, SupportsIndex, TypeAlias _ComparableNum: TypeAlias = int | float | Decimal | Real @@ -24,14 +23,14 @@ else: class Fraction(Rational): @overload def __new__( - cls: type[Self], numerator: int | Rational = 0, denominator: int | Rational | None = None, *, _normalize: bool = True + cls, numerator: int | Rational = 0, denominator: int | Rational | None = None, *, _normalize: bool = True ) -> Self: ... @overload - def __new__(cls: type[Self], __value: float | Decimal | str, *, _normalize: bool = True) -> Self: ... + def __new__(cls, __value: float | Decimal | str, *, _normalize: bool = True) -> Self: ... @classmethod - def from_float(cls: type[Self], f: float) -> Self: ... + def from_float(cls, f: float) -> Self: ... @classmethod - def from_decimal(cls: type[Self], dec: Decimal) -> Self: ... + def from_decimal(cls, dec: Decimal) -> Self: ... def limit_denominator(self, max_denominator: int = 1000000) -> Fraction: ... if sys.version_info >= (3, 8): def as_integer_ratio(self) -> tuple[int, int]: ... @@ -139,8 +138,8 @@ class Fraction(Rational): def __le__(a, b: _ComparableNum) -> bool: ... def __ge__(a, b: _ComparableNum) -> bool: ... def __bool__(a) -> bool: ... - def __copy__(self: Self) -> Self: ... - def __deepcopy__(self: Self, memo: Any) -> Self: ... + def __copy__(self) -> Self: ... + def __deepcopy__(self, memo: Any) -> Self: ... if sys.version_info >= (3, 11): def __int__(a, _index: Callable[[SupportsIndex], int] = ...) -> int: ... # Not actually defined within fractions.py, but provides more useful diff --git a/mypy/typeshed/stdlib/ftplib.pyi b/mypy/typeshed/stdlib/ftplib.pyi index 6c33f1409822..76d9dc02a5da 100644 --- a/mypy/typeshed/stdlib/ftplib.pyi +++ b/mypy/typeshed/stdlib/ftplib.pyi @@ -1,11 +1,11 @@ import sys -from _typeshed import Self, SupportsRead, SupportsReadline +from _typeshed import SupportsRead, SupportsReadline from collections.abc import Callable, Iterable, Iterator from socket import socket from ssl import SSLContext from types import TracebackType from typing import Any, TextIO -from typing_extensions import Literal +from typing_extensions import Literal, Self __all__ = ["FTP", "error_reply", "error_temp", "error_perm", "error_proto", "all_errors", "FTP_TLS"] @@ -36,7 +36,7 @@ class FTP: lastresp: str file: TextIO | None encoding: str - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/functools.pyi b/mypy/typeshed/stdlib/functools.pyi index 8778798144de..1214e349f605 100644 --- a/mypy/typeshed/stdlib/functools.pyi +++ b/mypy/typeshed/stdlib/functools.pyi @@ -1,9 +1,9 @@ import sys import types -from _typeshed import IdentityFunction, Self, SupportsAllComparisons, SupportsItems +from _typeshed import IdentityFunction, SupportsAllComparisons, SupportsItems from collections.abc import Callable, Hashable, Iterable, Sequence, Sized from typing import Any, Generic, NamedTuple, TypeVar, overload -from typing_extensions import Literal, TypeAlias, final +from typing_extensions import Literal, Self, TypeAlias, final if sys.version_info >= (3, 9): from types import GenericAlias @@ -79,7 +79,7 @@ class partial(Generic[_T]): def args(self) -> tuple[Any, ...]: ... @property def keywords(self) -> dict[str, Any]: ... - def __new__(cls: type[Self], __func: Callable[..., _T], *args: Any, **kwargs: Any) -> Self: ... + def __new__(cls, __func: Callable[..., _T], *args: Any, **kwargs: Any) -> Self: ... def __call__(__self, *args: Any, **kwargs: Any) -> _T: ... if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any) -> GenericAlias: ... @@ -111,11 +111,11 @@ class _SingleDispatchCallable(Generic[_T]): # @fun.register(complex) # def _(arg, verbose=False): ... @overload - def register(self, cls: type[Any], func: None = ...) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... + def register(self, cls: type[Any], func: None = None) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... # @fun.register # def _(arg: int, verbose=False): @overload - def register(self, cls: Callable[..., _T], func: None = ...) -> Callable[..., _T]: ... + def register(self, cls: Callable[..., _T], func: None = None) -> Callable[..., _T]: ... # fun.register(int, lambda x: x) @overload def register(self, cls: type[Any], func: Callable[..., _T]) -> Callable[..., _T]: ... diff --git a/mypy/typeshed/stdlib/hashlib.pyi b/mypy/typeshed/stdlib/hashlib.pyi index 8292e319330a..18b1ab549764 100644 --- a/mypy/typeshed/stdlib/hashlib.pyi +++ b/mypy/typeshed/stdlib/hashlib.pyi @@ -1,8 +1,8 @@ import sys -from _typeshed import ReadableBuffer, Self +from _typeshed import ReadableBuffer from collections.abc import Callable, Set as AbstractSet from typing import Protocol -from typing_extensions import final +from typing_extensions import Self, final if sys.version_info >= (3, 11): __all__ = ( @@ -56,7 +56,7 @@ class _Hash: @property def name(self) -> str: ... def __init__(self, data: ReadableBuffer = ...) -> None: ... - def copy(self: Self) -> Self: ... + def copy(self) -> Self: ... def digest(self) -> bytes: ... def hexdigest(self) -> str: ... def update(self, __data: ReadableBuffer) -> None: ... diff --git a/mypy/typeshed/stdlib/heapq.pyi b/mypy/typeshed/stdlib/heapq.pyi index 9d7815507ea5..61418b3704d6 100644 --- a/mypy/typeshed/stdlib/heapq.pyi +++ b/mypy/typeshed/stdlib/heapq.pyi @@ -2,12 +2,13 @@ from _heapq import * from _typeshed import SupportsRichComparison from collections.abc import Callable, Iterable from typing import Any, TypeVar +from typing_extensions import Final __all__ = ["heappush", "heappop", "heapify", "heapreplace", "merge", "nlargest", "nsmallest", "heappushpop"] _S = TypeVar("_S") -__about__: str +__about__: Final[str] def merge( *iterables: Iterable[_S], key: Callable[[_S], SupportsRichComparison] | None = None, reverse: bool = False diff --git a/mypy/typeshed/stdlib/http/client.pyi b/mypy/typeshed/stdlib/http/client.pyi index bb641875e55b..b1506b50e750 100644 --- a/mypy/typeshed/stdlib/http/client.pyi +++ b/mypy/typeshed/stdlib/http/client.pyi @@ -2,11 +2,11 @@ import email.message import io import ssl import types -from _typeshed import ReadableBuffer, Self, SupportsRead, WriteableBuffer +from _typeshed import ReadableBuffer, SupportsRead, WriteableBuffer from collections.abc import Callable, Iterable, Iterator, Mapping from socket import socket from typing import Any, BinaryIO, TypeVar, overload -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias __all__ = [ "HTTPResponse", @@ -127,7 +127,7 @@ class HTTPResponse(io.BufferedIOBase, BinaryIO): def getheaders(self) -> list[tuple[str, str]]: ... def isclosed(self) -> bool: ... def __iter__(self) -> Iterator[bytes]: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/imaplib.pyi b/mypy/typeshed/stdlib/imaplib.pyi index 8016d8bec5cd..1c2112dd37c8 100644 --- a/mypy/typeshed/stdlib/imaplib.pyi +++ b/mypy/typeshed/stdlib/imaplib.pyi @@ -1,7 +1,7 @@ import subprocess import sys import time -from _typeshed import ReadableBuffer, Self, _BufferWithLen +from _typeshed import ReadableBuffer, _BufferWithLen from builtins import list as _list # conflicts with a method named "list" from collections.abc import Callable from datetime import datetime @@ -10,7 +10,7 @@ from socket import socket as _socket from ssl import SSLContext, SSLSocket from types import TracebackType from typing import IO, Any, SupportsAbs, SupportsInt -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias __all__ = ["IMAP4", "IMAP4_stream", "Internaldate2tuple", "Int2AP", "ParseFlags", "Time2Internaldate", "IMAP4_SSL"] @@ -69,7 +69,7 @@ class IMAP4: def delete(self, mailbox: str) -> _CommandResults: ... def deleteacl(self, mailbox: str, who: str) -> _CommandResults: ... def enable(self, capability: str) -> _CommandResults: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, t: type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ... def expunge(self) -> _CommandResults: ... def fetch(self, message_set: str, message_parts: str) -> tuple[str, _AnyResponseData]: ... diff --git a/mypy/typeshed/stdlib/importlib/abc.pyi b/mypy/typeshed/stdlib/importlib/abc.pyi index 78b79267d06e..3d0c2d38c4e9 100644 --- a/mypy/typeshed/stdlib/importlib/abc.pyi +++ b/mypy/typeshed/stdlib/importlib/abc.pyi @@ -133,7 +133,7 @@ if sys.version_info >= (3, 9): @overload @abstractmethod def open( - self, mode: OpenBinaryMode, buffering: Literal[0], encoding: None = ..., errors: None = ..., newline: None = ... + self, mode: OpenBinaryMode, buffering: Literal[0], encoding: None = None, errors: None = None, newline: None = None ) -> FileIO: ... # Buffering is on: return BufferedRandom, BufferedReader, or BufferedWriter @overload @@ -142,9 +142,9 @@ if sys.version_info >= (3, 9): self, mode: OpenBinaryModeUpdating, buffering: Literal[-1, 1] = ..., - encoding: None = ..., - errors: None = ..., - newline: None = ..., + encoding: None = None, + errors: None = None, + newline: None = None, ) -> BufferedRandom: ... @overload @abstractmethod @@ -152,9 +152,9 @@ if sys.version_info >= (3, 9): self, mode: OpenBinaryModeWriting, buffering: Literal[-1, 1] = ..., - encoding: None = ..., - errors: None = ..., - newline: None = ..., + encoding: None = None, + errors: None = None, + newline: None = None, ) -> BufferedWriter: ... @overload @abstractmethod @@ -162,15 +162,15 @@ if sys.version_info >= (3, 9): self, mode: OpenBinaryModeReading, buffering: Literal[-1, 1] = ..., - encoding: None = ..., - errors: None = ..., - newline: None = ..., + encoding: None = None, + errors: None = None, + newline: None = None, ) -> BufferedReader: ... # Buffering cannot be determined: fall back to BinaryIO @overload @abstractmethod def open( - self, mode: OpenBinaryMode, buffering: int = ..., encoding: None = ..., errors: None = ..., newline: None = ... + self, mode: OpenBinaryMode, buffering: int = ..., encoding: None = None, errors: None = None, newline: None = None ) -> BinaryIO: ... # Fallback if mode is not specified @overload diff --git a/mypy/typeshed/stdlib/importlib/metadata/__init__.pyi b/mypy/typeshed/stdlib/importlib/metadata/__init__.pyi index cc93aaeca365..083453cd3c9a 100644 --- a/mypy/typeshed/stdlib/importlib/metadata/__init__.pyi +++ b/mypy/typeshed/stdlib/importlib/metadata/__init__.pyi @@ -1,7 +1,7 @@ import abc import pathlib import sys -from _typeshed import Self, StrPath +from _typeshed import StrPath from collections.abc import Iterable, Mapping from email.message import Message from importlib.abc import MetaPathFinder @@ -9,6 +9,7 @@ from os import PathLike from pathlib import Path from re import Pattern from typing import Any, ClassVar, NamedTuple, overload +from typing_extensions import Self __all__ = [ "Distribution", @@ -86,13 +87,13 @@ if sys.version_info >= (3, 10): class SelectableGroups(dict[str, EntryPoints]): # use as dict is deprecated since 3.10 @classmethod - def load(cls: type[Self], eps: Iterable[EntryPoint]) -> Self: ... + def load(cls, eps: Iterable[EntryPoint]) -> Self: ... @property def groups(self) -> set[str]: ... @property def names(self) -> set[str]: ... @overload - def select(self: Self) -> Self: ... # type: ignore[misc] + def select(self) -> Self: ... # type: ignore[misc] @overload def select( self, @@ -132,7 +133,7 @@ class Distribution: @overload @classmethod def discover( - cls, *, context: None = ..., name: str | None = ..., path: list[str] = ..., **kwargs: Any + cls, *, context: None = None, name: str | None = ..., path: list[str] = ..., **kwargs: Any ) -> Iterable[Distribution]: ... @staticmethod def at(path: StrPath) -> PathDistribution: ... @@ -185,7 +186,7 @@ def distribution(distribution_name: str) -> Distribution: ... def distributions(*, context: DistributionFinder.Context) -> Iterable[Distribution]: ... @overload def distributions( - *, context: None = ..., name: str | None = ..., path: list[str] = ..., **kwargs: Any + *, context: None = None, name: str | None = ..., path: list[str] = ..., **kwargs: Any ) -> Iterable[Distribution]: ... if sys.version_info >= (3, 10): diff --git a/mypy/typeshed/stdlib/inspect.pyi b/mypy/typeshed/stdlib/inspect.pyi index 3b82e0b0af2a..2525ef4968ec 100644 --- a/mypy/typeshed/stdlib/inspect.pyi +++ b/mypy/typeshed/stdlib/inspect.pyi @@ -2,7 +2,6 @@ import dis import enum import sys import types -from _typeshed import Self from collections import OrderedDict from collections.abc import AsyncGenerator, Awaitable, Callable, Coroutine, Generator, Mapping, Sequence, Set as AbstractSet from types import ( @@ -25,8 +24,8 @@ from types import ( TracebackType, WrapperDescriptorType, ) -from typing import Any, ClassVar, NamedTuple, Protocol, TypeVar, Union, overload -from typing_extensions import Literal, ParamSpec, TypeAlias, TypeGuard +from typing import Any, ClassVar, NamedTuple, Protocol, TypeVar, overload +from typing_extensions import Literal, ParamSpec, Self, TypeAlias, TypeGuard if sys.version_info >= (3, 11): __all__ = [ @@ -264,9 +263,9 @@ def isdatadescriptor(object: object) -> TypeGuard[_SupportsSet[Any, Any] | _Supp # # Retrieving source code # -_SourceObjectType: TypeAlias = Union[ - ModuleType, type[Any], MethodType, FunctionType, TracebackType, FrameType, CodeType, Callable[..., Any] -] +_SourceObjectType: TypeAlias = ( + ModuleType | type[Any] | MethodType | FunctionType | TracebackType | FrameType | CodeType | Callable[..., Any] +) def findsource(object: _SourceObjectType) -> tuple[list[str], int]: ... def getabsfile(object: _SourceObjectType, _filename: str | None = None) -> str: ... @@ -313,13 +312,11 @@ class Signature: def return_annotation(self) -> Any: ... def bind(self, *args: Any, **kwargs: Any) -> BoundArguments: ... def bind_partial(self, *args: Any, **kwargs: Any) -> BoundArguments: ... - def replace( - self: Self, *, parameters: Sequence[Parameter] | type[_void] | None = ..., return_annotation: Any = ... - ) -> Self: ... + def replace(self, *, parameters: Sequence[Parameter] | type[_void] | None = ..., return_annotation: Any = ...) -> Self: ... if sys.version_info >= (3, 10): @classmethod def from_callable( - cls: type[Self], + cls, obj: _IntrospectableCallable, *, follow_wrapped: bool = True, @@ -329,7 +326,7 @@ class Signature: ) -> Self: ... else: @classmethod - def from_callable(cls: type[Self], obj: _IntrospectableCallable, *, follow_wrapped: bool = True) -> Self: ... + def from_callable(cls, obj: _IntrospectableCallable, *, follow_wrapped: bool = True) -> Self: ... def __eq__(self, other: object) -> bool: ... @@ -372,7 +369,7 @@ class Parameter: @property def annotation(self) -> Any: ... def replace( - self: Self, + self, *, name: str | type[_void] = ..., kind: _ParameterKind | type[_void] = ..., @@ -493,7 +490,7 @@ if sys.version_info >= (3, 11): class Traceback(_Traceback): positions: dis.Positions | None def __new__( - cls: type[Self], + cls, filename: str, lineno: int, function: str, @@ -514,7 +511,7 @@ if sys.version_info >= (3, 11): class FrameInfo(_FrameInfo): positions: dis.Positions | None def __new__( - cls: type[Self], + cls, frame: FrameType, filename: str, lineno: int, diff --git a/mypy/typeshed/stdlib/io.pyi b/mypy/typeshed/stdlib/io.pyi index 6e1b4be77b07..c3e07bacbe5a 100644 --- a/mypy/typeshed/stdlib/io.pyi +++ b/mypy/typeshed/stdlib/io.pyi @@ -2,12 +2,12 @@ import abc import builtins import codecs import sys -from _typeshed import FileDescriptorOrPath, ReadableBuffer, Self, WriteableBuffer +from _typeshed import FileDescriptorOrPath, ReadableBuffer, WriteableBuffer from collections.abc import Callable, Iterable, Iterator from os import _Opener from types import TracebackType from typing import IO, Any, BinaryIO, TextIO -from typing_extensions import Literal +from typing_extensions import Literal, Self __all__ = [ "BlockingIOError", @@ -51,7 +51,7 @@ class UnsupportedOperation(OSError, ValueError): ... class IOBase(metaclass=abc.ABCMeta): def __iter__(self) -> Iterator[bytes]: ... def __next__(self) -> bytes: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... @@ -100,7 +100,7 @@ class FileIO(RawIOBase, BinaryIO): def closefd(self) -> bool: ... def write(self, __b: ReadableBuffer) -> int: ... def read(self, __size: int = -1) -> bytes: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... class BytesIO(BufferedIOBase, BinaryIO): def __init__(self, initial_bytes: ReadableBuffer = ...) -> None: ... @@ -108,23 +108,23 @@ class BytesIO(BufferedIOBase, BinaryIO): # to allow BytesIO sub-classes to add this field, as it is defined # as a read-only property on IO[]. name: Any - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def getvalue(self) -> bytes: ... def getbuffer(self) -> memoryview: ... def read1(self, __size: int | None = -1) -> bytes: ... class BufferedReader(BufferedIOBase, BinaryIO): - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... def peek(self, __size: int = 0) -> bytes: ... class BufferedWriter(BufferedIOBase, BinaryIO): - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... def write(self, __buffer: ReadableBuffer) -> int: ... class BufferedRandom(BufferedReader, BufferedWriter): - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def seek(self, __target: int, __whence: int = 0) -> int: ... # stubtest needs this class BufferedRWPair(BufferedIOBase): @@ -172,7 +172,7 @@ class TextIOWrapper(TextIOBase, TextIO): write_through: bool | None = None, ) -> None: ... # These are inherited from TextIOBase, but must exist in the stub to satisfy mypy. - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __iter__(self) -> Iterator[str]: ... # type: ignore[override] def __next__(self) -> str: ... # type: ignore[override] def writelines(self, __lines: Iterable[str]) -> None: ... # type: ignore[override] diff --git a/mypy/typeshed/stdlib/ipaddress.pyi b/mypy/typeshed/stdlib/ipaddress.pyi index 1de945db5d30..9f9662137765 100644 --- a/mypy/typeshed/stdlib/ipaddress.pyi +++ b/mypy/typeshed/stdlib/ipaddress.pyi @@ -1,8 +1,7 @@ import sys -from _typeshed import Self from collections.abc import Container, Iterable, Iterator from typing import Any, Generic, SupportsInt, TypeVar, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias # Undocumented length constants IPV4LENGTH: Literal[32] @@ -34,20 +33,20 @@ class _IPAddressBase: class _BaseAddress(_IPAddressBase, SupportsInt): def __init__(self, address: object) -> None: ... - def __add__(self: Self, other: int) -> Self: ... + def __add__(self, other: int) -> Self: ... def __int__(self) -> int: ... - def __sub__(self: Self, other: int) -> Self: ... + def __sub__(self, other: int) -> Self: ... def __format__(self, fmt: str) -> str: ... def __eq__(self, other: object) -> bool: ... - def __lt__(self: Self, other: Self) -> bool: ... + def __lt__(self, other: Self) -> bool: ... if sys.version_info >= (3, 11): - def __ge__(self: Self, other: Self) -> bool: ... - def __gt__(self: Self, other: Self) -> bool: ... - def __le__(self: Self, other: Self) -> bool: ... + def __ge__(self, other: Self) -> bool: ... + def __gt__(self, other: Self) -> bool: ... + def __le__(self, other: Self) -> bool: ... else: - def __ge__(self: Self, other: Self, NotImplemented: Any = ...) -> bool: ... - def __gt__(self: Self, other: Self, NotImplemented: Any = ...) -> bool: ... - def __le__(self: Self, other: Self, NotImplemented: Any = ...) -> bool: ... + def __ge__(self, other: Self, NotImplemented: Any = ...) -> bool: ... + def __gt__(self, other: Self, NotImplemented: Any = ...) -> bool: ... + def __le__(self, other: Self, NotImplemented: Any = ...) -> bool: ... @property def is_global(self) -> bool: ... @@ -76,20 +75,20 @@ class _BaseNetwork(_IPAddressBase, Container[_A], Iterable[_A], Generic[_A]): def __getitem__(self, n: int) -> _A: ... def __iter__(self) -> Iterator[_A]: ... def __eq__(self, other: object) -> bool: ... - def __lt__(self: Self, other: Self) -> bool: ... + def __lt__(self, other: Self) -> bool: ... if sys.version_info >= (3, 11): - def __ge__(self: Self, other: Self) -> bool: ... - def __gt__(self: Self, other: Self) -> bool: ... - def __le__(self: Self, other: Self) -> bool: ... + def __ge__(self, other: Self) -> bool: ... + def __gt__(self, other: Self) -> bool: ... + def __le__(self, other: Self) -> bool: ... else: - def __ge__(self: Self, other: Self, NotImplemented: Any = ...) -> bool: ... - def __gt__(self: Self, other: Self, NotImplemented: Any = ...) -> bool: ... - def __le__(self: Self, other: Self, NotImplemented: Any = ...) -> bool: ... + def __ge__(self, other: Self, NotImplemented: Any = ...) -> bool: ... + def __gt__(self, other: Self, NotImplemented: Any = ...) -> bool: ... + def __le__(self, other: Self, NotImplemented: Any = ...) -> bool: ... - def address_exclude(self: Self, other: Self) -> Iterator[Self]: ... + def address_exclude(self, other: Self) -> Iterator[Self]: ... @property def broadcast_address(self) -> _A: ... - def compare_networks(self: Self, other: Self) -> int: ... + def compare_networks(self, other: Self) -> int: ... def hosts(self) -> Iterator[_A]: ... @property def is_global(self) -> bool: ... @@ -112,10 +111,10 @@ class _BaseNetwork(_IPAddressBase, Container[_A], Iterable[_A], Generic[_A]): def overlaps(self, other: _BaseNetwork[IPv4Address] | _BaseNetwork[IPv6Address]) -> bool: ... @property def prefixlen(self) -> int: ... - def subnet_of(self: Self, other: Self) -> bool: ... - def supernet_of(self: Self, other: Self) -> bool: ... - def subnets(self: Self, prefixlen_diff: int = 1, new_prefix: int | None = None) -> Iterator[Self]: ... - def supernet(self: Self, prefixlen_diff: int = 1, new_prefix: int | None = None) -> Self: ... + def subnet_of(self, other: Self) -> bool: ... + def supernet_of(self, other: Self) -> bool: ... + def subnets(self, prefixlen_diff: int = 1, new_prefix: int | None = None) -> Iterator[Self]: ... + def supernet(self, prefixlen_diff: int = 1, new_prefix: int | None = None) -> Self: ... @property def with_hostmask(self) -> str: ... @property diff --git a/mypy/typeshed/stdlib/itertools.pyi b/mypy/typeshed/stdlib/itertools.pyi index a16827a3adb8..c7b92c3aebb5 100644 --- a/mypy/typeshed/stdlib/itertools.pyi +++ b/mypy/typeshed/stdlib/itertools.pyi @@ -1,8 +1,7 @@ import sys -from _typeshed import Self from collections.abc import Callable, Iterable, Iterator from typing import Any, Generic, SupportsComplex, SupportsFloat, SupportsInt, TypeVar, overload -from typing_extensions import Literal, SupportsIndex, TypeAlias +from typing_extensions import Literal, Self, SupportsIndex, TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias @@ -32,12 +31,12 @@ class count(Iterator[_N], Generic[_N]): @overload def __new__(cls, *, step: _N) -> count[_N]: ... def __next__(self) -> _N: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... class cycle(Iterator[_T], Generic[_T]): def __init__(self, __iterable: Iterable[_T]) -> None: ... def __next__(self) -> _T: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... class repeat(Iterator[_T], Generic[_T]): @overload @@ -45,25 +44,25 @@ class repeat(Iterator[_T], Generic[_T]): @overload def __init__(self, object: _T, times: int) -> None: ... def __next__(self) -> _T: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __length_hint__(self) -> int: ... class accumulate(Iterator[_T], Generic[_T]): if sys.version_info >= (3, 8): @overload - def __init__(self, iterable: Iterable[_T], func: None = ..., *, initial: _T | None = ...) -> None: ... + def __init__(self, iterable: Iterable[_T], func: None = None, *, initial: _T | None = ...) -> None: ... @overload def __init__(self, iterable: Iterable[_S], func: Callable[[_T, _S], _T], *, initial: _T | None = ...) -> None: ... else: def __init__(self, iterable: Iterable[_T], func: Callable[[_T, _T], _T] | None = ...) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T: ... class chain(Iterator[_T], Generic[_T]): def __init__(self, *iterables: Iterable[_T]) -> None: ... def __next__(self) -> _T: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... @classmethod # We use type[Any] and not type[_S] to not lose the type inference from __iterable def from_iterable(cls: type[Any], __iterable: Iterable[Iterable[_S]]) -> chain[_S]: ... @@ -72,25 +71,25 @@ class chain(Iterator[_T], Generic[_T]): class compress(Iterator[_T], Generic[_T]): def __init__(self, data: Iterable[_T], selectors: Iterable[Any]) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T: ... class dropwhile(Iterator[_T], Generic[_T]): def __init__(self, __predicate: _Predicate[_T], __iterable: Iterable[_T]) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T: ... class filterfalse(Iterator[_T], Generic[_T]): def __init__(self, __predicate: _Predicate[_T] | None, __iterable: Iterable[_T]) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T: ... class groupby(Iterator[tuple[_T, Iterator[_S]]], Generic[_T, _S]): @overload - def __new__(cls, iterable: Iterable[_T1], key: None = ...) -> groupby[_T1, _T1]: ... + def __new__(cls, iterable: Iterable[_T1], key: None = None) -> groupby[_T1, _T1]: ... @overload def __new__(cls, iterable: Iterable[_T1], key: Callable[[_T1], _T2]) -> groupby[_T2, _T1]: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> tuple[_T, Iterator[_S]]: ... class islice(Iterator[_T], Generic[_T]): @@ -98,17 +97,17 @@ class islice(Iterator[_T], Generic[_T]): def __init__(self, __iterable: Iterable[_T], __stop: int | None) -> None: ... @overload def __init__(self, __iterable: Iterable[_T], __start: int | None, __stop: int | None, __step: int | None = ...) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T: ... class starmap(Iterator[_T], Generic[_T]): def __init__(self, __function: Callable[..., _T], __iterable: Iterable[Iterable[Any]]) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T: ... class takewhile(Iterator[_T], Generic[_T]): def __init__(self, __predicate: _Predicate[_T], __iterable: Iterable[_T]) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T: ... def tee(__iterable: Iterable[_T], __n: int = 2) -> tuple[Iterator[_T], ...]: ... @@ -190,7 +189,7 @@ class zip_longest(Iterator[_T_co], Generic[_T_co]): *iterables: Iterable[_T], fillvalue: _T, ) -> zip_longest[tuple[_T, ...]]: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... class product(Iterator[_T_co], Generic[_T_co]): @@ -239,12 +238,12 @@ class product(Iterator[_T_co], Generic[_T_co]): def __new__(cls, *iterables: Iterable[_T1], repeat: int) -> product[tuple[_T1, ...]]: ... @overload def __new__(cls, *iterables: Iterable[Any], repeat: int = ...) -> product[tuple[Any, ...]]: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... class permutations(Iterator[tuple[_T, ...]], Generic[_T]): def __init__(self, iterable: Iterable[_T], r: int | None = ...) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> tuple[_T, ...]: ... class combinations(Iterator[_T_co], Generic[_T_co]): @@ -258,22 +257,22 @@ class combinations(Iterator[_T_co], Generic[_T_co]): def __new__(cls, iterable: Iterable[_T], r: Literal[5]) -> combinations[tuple[_T, _T, _T, _T, _T]]: ... @overload def __new__(cls, iterable: Iterable[_T], r: int) -> combinations[tuple[_T, ...]]: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... class combinations_with_replacement(Iterator[tuple[_T, ...]], Generic[_T]): def __init__(self, iterable: Iterable[_T], r: int) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> tuple[_T, ...]: ... if sys.version_info >= (3, 10): class pairwise(Iterator[_T_co], Generic[_T_co]): def __new__(cls, __iterable: Iterable[_T]) -> pairwise[tuple[_T, _T]]: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... if sys.version_info >= (3, 12): class batched(Iterator[_T_co], Generic[_T_co]): - def __new__(cls: type[Self], iterable: Iterable[_T_co], n: int) -> Self: ... - def __iter__(self: Self) -> Self: ... + def __new__(cls, iterable: Iterable[_T_co], n: int) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> tuple[_T_co, ...]: ... diff --git a/mypy/typeshed/stdlib/keyword.pyi b/mypy/typeshed/stdlib/keyword.pyi index c17c58012fd1..46c386048858 100644 --- a/mypy/typeshed/stdlib/keyword.pyi +++ b/mypy/typeshed/stdlib/keyword.pyi @@ -1,5 +1,6 @@ import sys from collections.abc import Sequence +from typing_extensions import Final if sys.version_info >= (3, 9): __all__ = ["iskeyword", "issoftkeyword", "kwlist", "softkwlist"] @@ -8,8 +9,13 @@ else: def iskeyword(s: str) -> bool: ... -kwlist: Sequence[str] +# a list at runtime, but you're not meant to mutate it; +# type it as a sequence +kwlist: Final[Sequence[str]] if sys.version_info >= (3, 9): def issoftkeyword(s: str) -> bool: ... - softkwlist: Sequence[str] + + # a list at runtime, but you're not meant to mutate it; + # type it as a sequence + softkwlist: Final[Sequence[str]] diff --git a/mypy/typeshed/stdlib/lib2to3/pgen2/grammar.pyi b/mypy/typeshed/stdlib/lib2to3/pgen2/grammar.pyi index aa0dd687659d..bef0a7922683 100644 --- a/mypy/typeshed/stdlib/lib2to3/pgen2/grammar.pyi +++ b/mypy/typeshed/stdlib/lib2to3/pgen2/grammar.pyi @@ -1,5 +1,5 @@ -from _typeshed import Self, StrPath -from typing_extensions import TypeAlias +from _typeshed import StrPath +from typing_extensions import Self, TypeAlias _Label: TypeAlias = tuple[int, str | None] _DFA: TypeAlias = list[list[tuple[int, int]]] @@ -17,7 +17,7 @@ class Grammar: start: int def dump(self, filename: StrPath) -> None: ... def load(self, filename: StrPath) -> None: ... - def copy(self: Self) -> Self: ... + def copy(self) -> Self: ... def report(self) -> None: ... opmap_raw: str diff --git a/mypy/typeshed/stdlib/lib2to3/pytree.pyi b/mypy/typeshed/stdlib/lib2to3/pytree.pyi index 5cf7db146e46..4f756c9768db 100644 --- a/mypy/typeshed/stdlib/lib2to3/pytree.pyi +++ b/mypy/typeshed/stdlib/lib2to3/pytree.pyi @@ -1,8 +1,7 @@ -from _typeshed import Self from collections.abc import Iterator from lib2to3.pgen2.grammar import Grammar from typing import Any -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias _NL: TypeAlias = Node | Leaf _Context: TypeAlias = tuple[str, int, int] @@ -21,8 +20,8 @@ class Base: was_changed: bool was_checked: bool def __eq__(self, other: object) -> bool: ... - def _eq(self: Self, other: Self) -> bool: ... - def clone(self: Self) -> Self: ... + def _eq(self, other: Self) -> bool: ... + def clone(self) -> Self: ... def post_order(self) -> Iterator[_NL]: ... def pre_order(self) -> Iterator[_NL]: ... def replace(self, new: _NL | list[_NL]) -> None: ... diff --git a/mypy/typeshed/stdlib/logging/__init__.pyi b/mypy/typeshed/stdlib/logging/__init__.pyi index 231700653a32..c74afa45ded1 100644 --- a/mypy/typeshed/stdlib/logging/__init__.pyi +++ b/mypy/typeshed/stdlib/logging/__init__.pyi @@ -1,14 +1,14 @@ import sys import threading -from _typeshed import Self, StrPath, SupportsWrite +from _typeshed import StrPath, SupportsWrite from collections.abc import Callable, Iterable, Mapping, MutableMapping, Sequence from io import TextIOWrapper from re import Pattern from string import Template from time import struct_time from types import FrameType, TracebackType -from typing import Any, ClassVar, Generic, TextIO, TypeVar, Union, overload -from typing_extensions import Literal, TypeAlias +from typing import Any, ClassVar, Generic, TextIO, TypeVar, overload +from typing_extensions import Literal, Self, TypeAlias if sys.version_info >= (3, 11): from types import GenericAlias @@ -61,7 +61,7 @@ __all__ = [ if sys.version_info >= (3, 11): __all__ += ["getLevelNamesMapping"] -_SysExcInfoType: TypeAlias = Union[tuple[type[BaseException], BaseException, TracebackType | None], tuple[None, None, None]] +_SysExcInfoType: TypeAlias = tuple[type[BaseException], BaseException, TracebackType | None] | tuple[None, None, None] _ExcInfoType: TypeAlias = None | bool | _SysExcInfoType | BaseException _ArgsType: TypeAlias = tuple[object, ...] | Mapping[str, object] _FilterType: TypeAlias = Filter | Callable[[LogRecord], bool] @@ -110,7 +110,7 @@ class Logger(Filterer): def setLevel(self, level: _Level) -> None: ... def isEnabledFor(self, level: int) -> bool: ... def getEffectiveLevel(self) -> int: ... - def getChild(self: Self, suffix: str) -> Self: ... # see python/typing#980 + def getChild(self, suffix: str) -> Self: ... # see python/typing#980 if sys.version_info >= (3, 8): def debug( self, diff --git a/mypy/typeshed/stdlib/lzma.pyi b/mypy/typeshed/stdlib/lzma.pyi index 2feb28a8e743..34bd6f3f8db1 100644 --- a/mypy/typeshed/stdlib/lzma.pyi +++ b/mypy/typeshed/stdlib/lzma.pyi @@ -1,8 +1,8 @@ import io -from _typeshed import ReadableBuffer, Self, StrOrBytesPath +from _typeshed import ReadableBuffer, StrOrBytesPath from collections.abc import Mapping, Sequence from typing import IO, Any, TextIO, overload -from typing_extensions import Literal, TypeAlias, final +from typing_extensions import Literal, Self, TypeAlias, final __all__ = [ "CHECK_NONE", @@ -115,7 +115,7 @@ class LZMAFile(io.BufferedIOBase, IO[bytes]): preset: int | None = None, filters: _FilterChain | None = None, ) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def peek(self, size: int = -1) -> bytes: ... def read(self, size: int | None = -1) -> bytes: ... def read1(self, size: int = -1) -> bytes: ... diff --git a/mypy/typeshed/stdlib/mailbox.pyi b/mypy/typeshed/stdlib/mailbox.pyi index 2fe9060e7b7c..8053fad88ea5 100644 --- a/mypy/typeshed/stdlib/mailbox.pyi +++ b/mypy/typeshed/stdlib/mailbox.pyi @@ -1,12 +1,12 @@ import email.message import io import sys -from _typeshed import Self, StrPath, SupportsNoArgReadline, SupportsRead +from _typeshed import StrPath, SupportsNoArgReadline, SupportsRead from abc import ABCMeta, abstractmethod from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence from types import TracebackType from typing import IO, Any, AnyStr, Generic, Protocol, TypeVar, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias @@ -235,7 +235,7 @@ class _ProxyFile(Generic[AnyStr]): def tell(self) -> int: ... def seek(self, offset: int, whence: int = 0) -> None: ... def close(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None: ... def readable(self) -> bool: ... def writable(self) -> bool: ... diff --git a/mypy/typeshed/stdlib/marshal.pyi b/mypy/typeshed/stdlib/marshal.pyi index da5d1a95a6f6..21f05c908479 100644 --- a/mypy/typeshed/stdlib/marshal.pyi +++ b/mypy/typeshed/stdlib/marshal.pyi @@ -1,31 +1,31 @@ import builtins import types from _typeshed import ReadableBuffer, SupportsRead, SupportsWrite -from typing import Any, Union +from typing import Any from typing_extensions import TypeAlias version: int -_Marshallable: TypeAlias = Union[ +_Marshallable: TypeAlias = ( # handled in w_object() in marshal.c - None, - type[StopIteration], - builtins.ellipsis, - bool, + None + | type[StopIteration] + | builtins.ellipsis + | bool # handled in w_complex_object() in marshal.c - int, - float, - complex, - bytes, - str, - tuple[_Marshallable, ...], - list[Any], - dict[Any, Any], - set[Any], - frozenset[_Marshallable], - types.CodeType, - ReadableBuffer, -] + | int + | float + | complex + | bytes + | str + | tuple[_Marshallable, ...] + | list[Any] + | dict[Any, Any] + | set[Any] + | frozenset[_Marshallable] + | types.CodeType + | ReadableBuffer +) def dump(__value: _Marshallable, __file: SupportsWrite[bytes], __version: int = 4) -> None: ... def load(__file: SupportsRead[bytes]) -> Any: ... diff --git a/mypy/typeshed/stdlib/mmap.pyi b/mypy/typeshed/stdlib/mmap.pyi index 273cd0c6f4d4..c74ad3cda6db 100644 --- a/mypy/typeshed/stdlib/mmap.pyi +++ b/mypy/typeshed/stdlib/mmap.pyi @@ -1,7 +1,8 @@ import sys -from _typeshed import ReadableBuffer, Self, Unused +from _typeshed import ReadableBuffer, Unused from collections.abc import Iterable, Iterator, Sized from typing import NoReturn, overload +from typing_extensions import Self ACCESS_DEFAULT: int ACCESS_READ: int @@ -73,7 +74,7 @@ class mmap(Iterable[int], Sized): # Doesn't actually exist, but the object is actually iterable because it has __getitem__ and __len__, # so we claim that there is also an __iter__ to help type checkers. def __iter__(self) -> Iterator[int]: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... if sys.version_info >= (3, 8) and sys.platform != "win32": diff --git a/mypy/typeshed/stdlib/multiprocessing/connection.pyi b/mypy/typeshed/stdlib/multiprocessing/connection.pyi index 392e3168aaaa..d034373712e0 100644 --- a/mypy/typeshed/stdlib/multiprocessing/connection.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/connection.pyi @@ -1,15 +1,15 @@ import socket import sys import types -from _typeshed import ReadableBuffer, Self +from _typeshed import ReadableBuffer from collections.abc import Iterable -from typing import Any, Union -from typing_extensions import SupportsIndex, TypeAlias +from typing import Any +from typing_extensions import Self, SupportsIndex, TypeAlias __all__ = ["Client", "Listener", "Pipe", "wait"] # https://docs.python.org/3/library/multiprocessing.html#address-formats -_Address: TypeAlias = Union[str, tuple[str, int]] +_Address: TypeAlias = str | tuple[str, int] class _ConnectionBase: def __init__(self, handle: SupportsIndex, readable: bool = True, writable: bool = True) -> None: ... @@ -27,7 +27,7 @@ class _ConnectionBase: def recv_bytes_into(self, buf: Any, offset: int = 0) -> int: ... def recv(self) -> Any: ... def poll(self, timeout: float | None = 0.0) -> bool: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... @@ -47,7 +47,7 @@ class Listener: def address(self) -> _Address: ... @property def last_accepted(self) -> _Address | None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/multiprocessing/dummy/connection.pyi b/mypy/typeshed/stdlib/multiprocessing/dummy/connection.pyi index 1630472b3b06..fcd03a657319 100644 --- a/mypy/typeshed/stdlib/multiprocessing/dummy/connection.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/dummy/connection.pyi @@ -1,14 +1,13 @@ -from _typeshed import Self from queue import Queue from types import TracebackType -from typing import Any, Union -from typing_extensions import TypeAlias +from typing import Any +from typing_extensions import Self, TypeAlias __all__ = ["Client", "Listener", "Pipe"] families: list[None] -_Address: TypeAlias = Union[str, tuple[str, int]] +_Address: TypeAlias = str | tuple[str, int] class Connection: _in: Any @@ -17,7 +16,7 @@ class Connection: recv_bytes: Any send: Any send_bytes: Any - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, exc_tb: TracebackType | None ) -> None: ... @@ -29,7 +28,7 @@ class Listener: _backlog_queue: Queue[Any] | None @property def address(self) -> Queue[Any] | None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/multiprocessing/managers.pyi b/mypy/typeshed/stdlib/multiprocessing/managers.pyi index 1696714d187b..e035a1875650 100644 --- a/mypy/typeshed/stdlib/multiprocessing/managers.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/managers.pyi @@ -1,11 +1,11 @@ import queue import sys import threading -from _typeshed import Self, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT +from _typeshed import SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping, MutableSequence, Sequence from types import TracebackType from typing import Any, AnyStr, ClassVar, Generic, TypeVar, overload -from typing_extensions import SupportsIndex, TypeAlias +from typing_extensions import Self, SupportsIndex, TypeAlias from .connection import Connection from .context import BaseContext @@ -111,13 +111,13 @@ class BaseListProxy(BaseProxy, MutableSequence[_T]): # Use BaseListProxy[SupportsRichComparisonT] for the first overload rather than [SupportsRichComparison] # to work around invariance @overload - def sort(self: BaseListProxy[SupportsRichComparisonT], *, key: None = ..., reverse: bool = ...) -> None: ... + def sort(self: BaseListProxy[SupportsRichComparisonT], *, key: None = None, reverse: bool = ...) -> None: ... @overload def sort(self, *, key: Callable[[_T], SupportsRichComparison], reverse: bool = ...) -> None: ... class ListProxy(BaseListProxy[_T]): - def __iadd__(self: Self, __x: Iterable[_T]) -> Self: ... # type: ignore[override] - def __imul__(self: Self, __n: SupportsIndex) -> Self: ... # type: ignore[override] + def __iadd__(self, __x: Iterable[_T]) -> Self: ... # type: ignore[override] + def __imul__(self, __n: SupportsIndex) -> Self: ... # type: ignore[override] # Returned by BaseManager.get_server() class Server: @@ -165,7 +165,7 @@ class BaseManager: method_to_typeid: Mapping[str, str] | None = None, create_method: bool = True, ) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/multiprocessing/pool.pyi b/mypy/typeshed/stdlib/multiprocessing/pool.pyi index 3e2d0c3cd51e..a19dd555e254 100644 --- a/mypy/typeshed/stdlib/multiprocessing/pool.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/pool.pyi @@ -1,9 +1,8 @@ import sys -from _typeshed import Self from collections.abc import Callable, Iterable, Iterator, Mapping from types import TracebackType from typing import Any, Generic, TypeVar -from typing_extensions import Literal +from typing_extensions import Literal, Self if sys.version_info >= (3, 9): from types import GenericAlias @@ -62,7 +61,7 @@ class IMapIterator(Iterator[_T]): else: def __init__(self, cache: dict[int, IMapIterator[Any]]) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def next(self, timeout: float | None = None) -> _T: ... def __next__(self, timeout: float | None = None) -> _T: ... @@ -109,7 +108,7 @@ class Pool: def close(self) -> None: ... def terminate(self) -> None: ... def join(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/multiprocessing/shared_memory.pyi b/mypy/typeshed/stdlib/multiprocessing/shared_memory.pyi index 841c947360e8..ae6e2a0ed19f 100644 --- a/mypy/typeshed/stdlib/multiprocessing/shared_memory.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/shared_memory.pyi @@ -1,7 +1,7 @@ import sys -from _typeshed import Self from collections.abc import Iterable from typing import Any, Generic, TypeVar, overload +from typing_extensions import Self if sys.version_info >= (3, 9): from types import GenericAlias @@ -29,7 +29,7 @@ class ShareableList(Generic[_SLT]): def __init__(self, sequence: Iterable[_SLT], *, name: str | None = None) -> None: ... def __getitem__(self, position: int) -> _SLT: ... def __setitem__(self, position: int, value: _SLT) -> None: ... - def __reduce__(self: Self) -> tuple[Self, tuple[_SLT, ...]]: ... + def __reduce__(self) -> tuple[Self, tuple[_SLT, ...]]: ... def __len__(self) -> int: ... @property def format(self) -> str: ... diff --git a/mypy/typeshed/stdlib/nntplib.pyi b/mypy/typeshed/stdlib/nntplib.pyi index 02e743ea9d1e..f948c1430c90 100644 --- a/mypy/typeshed/stdlib/nntplib.pyi +++ b/mypy/typeshed/stdlib/nntplib.pyi @@ -2,11 +2,11 @@ import datetime import socket import ssl import sys -from _typeshed import Self, Unused +from _typeshed import Unused from builtins import list as _list # conflicts with a method named "list" from collections.abc import Iterable from typing import IO, Any, NamedTuple -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias __all__ = [ "NNTP", @@ -72,7 +72,7 @@ class NNTP: usenetrc: bool = False, timeout: float = ..., ) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... def getwelcome(self) -> str: ... def getcapabilities(self) -> dict[str, _list[str]]: ... diff --git a/mypy/typeshed/stdlib/os/__init__.pyi b/mypy/typeshed/stdlib/os/__init__.pyi index b1b9db9ae2a7..595b78789c6a 100644 --- a/mypy/typeshed/stdlib/os/__init__.pyi +++ b/mypy/typeshed/stdlib/os/__init__.pyi @@ -11,7 +11,6 @@ from _typeshed import ( OpenBinaryModeWriting, OpenTextMode, ReadableBuffer, - Self, StrOrBytesPath, StrPath, SupportsLenAndGetItem, @@ -26,7 +25,7 @@ from contextlib import AbstractContextManager from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper as _TextIOWrapper from subprocess import Popen from typing import IO, Any, AnyStr, BinaryIO, Generic, NoReturn, Protocol, TypeVar, overload, runtime_checkable -from typing_extensions import Final, Literal, TypeAlias, final +from typing_extensions import Final, Literal, Self, TypeAlias, final from . import path as _path @@ -245,9 +244,9 @@ class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]): # overloading MutableMapping.update in stdlib/typing.pyi # The type: ignore is needed due to incompatible __or__/__ior__ signatures @overload # type: ignore[misc] - def __ior__(self: Self, other: Mapping[AnyStr, AnyStr]) -> Self: ... + def __ior__(self, other: Mapping[AnyStr, AnyStr]) -> Self: ... @overload - def __ior__(self: Self, other: Iterable[tuple[AnyStr, AnyStr]]) -> Self: ... + def __ior__(self, other: Iterable[tuple[AnyStr, AnyStr]]) -> Self: ... environ: _Environ[str] if sys.platform != "win32": @@ -530,8 +529,8 @@ def fdopen( mode: OpenBinaryMode, buffering: Literal[0], encoding: None = None, - errors: None = ..., - newline: None = ..., + errors: None = None, + newline: None = None, closefd: bool = ..., opener: _Opener | None = ..., ) -> FileIO: ... @@ -541,8 +540,8 @@ def fdopen( mode: OpenBinaryModeUpdating, buffering: Literal[-1, 1] = -1, encoding: None = None, - errors: None = ..., - newline: None = ..., + errors: None = None, + newline: None = None, closefd: bool = ..., opener: _Opener | None = ..., ) -> BufferedRandom: ... @@ -552,8 +551,8 @@ def fdopen( mode: OpenBinaryModeWriting, buffering: Literal[-1, 1] = -1, encoding: None = None, - errors: None = ..., - newline: None = ..., + errors: None = None, + newline: None = None, closefd: bool = ..., opener: _Opener | None = ..., ) -> BufferedWriter: ... @@ -563,8 +562,8 @@ def fdopen( mode: OpenBinaryModeReading, buffering: Literal[-1, 1] = -1, encoding: None = None, - errors: None = ..., - newline: None = ..., + errors: None = None, + newline: None = None, closefd: bool = ..., opener: _Opener | None = ..., ) -> BufferedReader: ... @@ -574,8 +573,8 @@ def fdopen( mode: OpenBinaryMode, buffering: int = -1, encoding: None = None, - errors: None = ..., - newline: None = ..., + errors: None = None, + newline: None = None, closefd: bool = ..., opener: _Opener | None = ..., ) -> BinaryIO: ... @@ -958,7 +957,7 @@ if sys.platform != "win32": class sched_param(structseq[int], tuple[int]): if sys.version_info >= (3, 10): __match_args__: Final = ("sched_priority",) - def __new__(cls: type[Self], sched_priority: int) -> Self: ... + def __new__(cls, sched_priority: int) -> Self: ... @property def sched_priority(self) -> int: ... @@ -1001,7 +1000,7 @@ if sys.version_info >= (3, 8): path: str | None def __init__(self, path: str | None, cookie: _T, remove_dll_directory: Callable[[_T], object]) -> None: ... def close(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... def add_dll_directory(path: str) -> _AddedDllDirectory: ... diff --git a/mypy/typeshed/stdlib/pathlib.pyi b/mypy/typeshed/stdlib/pathlib.pyi index 5220a142fb13..114678ed574d 100644 --- a/mypy/typeshed/stdlib/pathlib.pyi +++ b/mypy/typeshed/stdlib/pathlib.pyi @@ -6,7 +6,6 @@ from _typeshed import ( OpenBinaryModeWriting, OpenTextMode, ReadableBuffer, - Self, StrOrBytesPath, StrPath, ) @@ -15,7 +14,7 @@ from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWra from os import PathLike, stat_result from types import TracebackType from typing import IO, Any, BinaryIO, overload -from typing_extensions import Literal +from typing_extensions import Literal, Self if sys.version_info >= (3, 9): from types import GenericAlias @@ -39,15 +38,15 @@ class PurePath(PathLike[str]): def suffixes(self) -> list[str]: ... @property def stem(self) -> str: ... - def __new__(cls: type[Self], *args: StrPath) -> Self: ... + def __new__(cls, *args: StrPath) -> Self: ... def __eq__(self, other: object) -> bool: ... def __fspath__(self) -> str: ... def __lt__(self, other: PurePath) -> bool: ... def __le__(self, other: PurePath) -> bool: ... def __gt__(self, other: PurePath) -> bool: ... def __ge__(self, other: PurePath) -> bool: ... - def __truediv__(self: Self, key: StrPath) -> Self: ... - def __rtruediv__(self: Self, key: StrPath) -> Self: ... + def __truediv__(self, key: StrPath) -> Self: ... + def __rtruediv__(self, key: StrPath) -> Self: ... def __bytes__(self) -> bytes: ... def as_posix(self) -> str: ... def as_uri(self) -> str: ... @@ -57,17 +56,17 @@ class PurePath(PathLike[str]): def is_relative_to(self, *other: StrPath) -> bool: ... def match(self, path_pattern: str) -> bool: ... - def relative_to(self: Self, *other: StrPath) -> Self: ... - def with_name(self: Self, name: str) -> Self: ... + def relative_to(self, *other: StrPath) -> Self: ... + def with_name(self, name: str) -> Self: ... if sys.version_info >= (3, 9): - def with_stem(self: Self, stem: str) -> Self: ... + def with_stem(self, stem: str) -> Self: ... - def with_suffix(self: Self, suffix: str) -> Self: ... - def joinpath(self: Self, *other: StrPath) -> Self: ... + def with_suffix(self, suffix: str) -> Self: ... + def joinpath(self, *other: StrPath) -> Self: ... @property - def parents(self: Self) -> Sequence[Self]: ... + def parents(self) -> Sequence[Self]: ... @property - def parent(self: Self) -> Self: ... + def parent(self) -> Self: ... if sys.version_info >= (3, 9) and sys.version_info < (3, 11): def __class_getitem__(cls, type: Any) -> GenericAlias: ... @@ -75,11 +74,11 @@ class PurePosixPath(PurePath): ... class PureWindowsPath(PurePath): ... class Path(PurePath): - def __new__(cls: type[Self], *args: StrPath, **kwargs: Any) -> Self: ... - def __enter__(self: Self) -> Self: ... + def __new__(cls, *args: StrPath, **kwargs: Any) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, t: type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ... @classmethod - def cwd(cls: type[Self]) -> Self: ... + def cwd(cls) -> Self: ... if sys.version_info >= (3, 10): def stat(self, *, follow_symlinks: bool = True) -> stat_result: ... def chmod(self, mode: int, *, follow_symlinks: bool = True) -> None: ... @@ -88,7 +87,7 @@ class Path(PurePath): def chmod(self, mode: int) -> None: ... def exists(self) -> bool: ... - def glob(self: Self, pattern: str) -> Generator[Self, None, None]: ... + def glob(self, pattern: str) -> Generator[Self, None, None]: ... def is_dir(self) -> bool: ... def is_file(self) -> bool: ... def is_symlink(self) -> bool: ... @@ -96,7 +95,7 @@ class Path(PurePath): def is_fifo(self) -> bool: ... def is_block_device(self) -> bool: ... def is_char_device(self) -> bool: ... - def iterdir(self: Self) -> Generator[Self, None, None]: ... + def iterdir(self) -> Generator[Self, None, None]: ... def lchmod(self, mode: int) -> None: ... def lstat(self) -> stat_result: ... def mkdir(self, mode: int = 0o777, parents: bool = False, exist_ok: bool = False) -> None: ... @@ -163,16 +162,16 @@ class Path(PurePath): def is_mount(self) -> bool: ... if sys.version_info >= (3, 9): - def readlink(self: Self) -> Self: ... + def readlink(self) -> Self: ... if sys.version_info >= (3, 8): - def rename(self: Self, target: str | PurePath) -> Self: ... - def replace(self: Self, target: str | PurePath) -> Self: ... + def rename(self, target: str | PurePath) -> Self: ... + def replace(self, target: str | PurePath) -> Self: ... else: def rename(self, target: str | PurePath) -> None: ... def replace(self, target: str | PurePath) -> None: ... - def resolve(self: Self, strict: bool = False) -> Self: ... - def rglob(self: Self, pattern: str) -> Generator[Self, None, None]: ... + def resolve(self, strict: bool = False) -> Self: ... + def rglob(self, pattern: str) -> Generator[Self, None, None]: ... def rmdir(self) -> None: ... def symlink_to(self, target: str | Path, target_is_directory: bool = False) -> None: ... if sys.version_info >= (3, 10): @@ -185,9 +184,9 @@ class Path(PurePath): def unlink(self) -> None: ... @classmethod - def home(cls: type[Self]) -> Self: ... - def absolute(self: Self) -> Self: ... - def expanduser(self: Self) -> Self: ... + def home(cls) -> Self: ... + def absolute(self) -> Self: ... + def expanduser(self) -> Self: ... def read_bytes(self) -> bytes: ... def read_text(self, encoding: str | None = None, errors: str | None = None) -> str: ... def samefile(self, other_path: StrPath) -> bool: ... @@ -202,7 +201,7 @@ class Path(PurePath): def link_to(self, target: StrOrBytesPath) -> None: ... if sys.version_info >= (3, 12): def walk( - self: Self, top_down: bool = ..., on_error: Callable[[OSError], object] | None = ..., follow_symlinks: bool = ... + self, top_down: bool = ..., on_error: Callable[[OSError], object] | None = ..., follow_symlinks: bool = ... ) -> Iterator[tuple[Self, list[str], list[str]]]: ... class PosixPath(Path, PurePosixPath): ... diff --git a/mypy/typeshed/stdlib/pdb.pyi b/mypy/typeshed/stdlib/pdb.pyi index a2b6636d8665..e2871bb54fa0 100644 --- a/mypy/typeshed/stdlib/pdb.pyi +++ b/mypy/typeshed/stdlib/pdb.pyi @@ -1,13 +1,12 @@ import signal import sys -from _typeshed import Self from bdb import Bdb from cmd import Cmd from collections.abc import Callable, Iterable, Mapping, Sequence from inspect import _SourceObjectType from types import CodeType, FrameType, TracebackType from typing import IO, Any, ClassVar, TypeVar -from typing_extensions import ParamSpec +from typing_extensions import ParamSpec, Self __all__ = ["run", "pm", "Pdb", "runeval", "runctx", "runcall", "set_trace", "post_mortem", "help"] @@ -173,4 +172,4 @@ def getsourcelines(obj: _SourceObjectType) -> tuple[list[str], int]: ... def lasti2lineno(code: CodeType, lasti: int) -> int: ... class _rstr(str): - def __repr__(self: Self) -> Self: ... + def __repr__(self) -> Self: ... diff --git a/mypy/typeshed/stdlib/pickle.pyi b/mypy/typeshed/stdlib/pickle.pyi index dc098cae97b7..57c4cb03e484 100644 --- a/mypy/typeshed/stdlib/pickle.pyi +++ b/mypy/typeshed/stdlib/pickle.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import ReadableBuffer, SupportsWrite from collections.abc import Callable, Iterable, Iterator, Mapping -from typing import Any, ClassVar, Protocol, SupportsBytes, Union +from typing import Any, ClassVar, Protocol, SupportsBytes from typing_extensions import SupportsIndex, TypeAlias, final __all__ = [ @@ -142,13 +142,13 @@ class PickleError(Exception): ... class PicklingError(PickleError): ... class UnpicklingError(PickleError): ... -_ReducedType: TypeAlias = Union[ - 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], -] +_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 diff --git a/mypy/typeshed/stdlib/plistlib.pyi b/mypy/typeshed/stdlib/plistlib.pyi index 54ce3dc61abc..5b76c935f76e 100644 --- a/mypy/typeshed/stdlib/plistlib.pyi +++ b/mypy/typeshed/stdlib/plistlib.pyi @@ -1,9 +1,10 @@ import sys -from _typeshed import ReadableBuffer, Self +from _typeshed import ReadableBuffer from collections.abc import Mapping, MutableMapping from datetime import datetime from enum import Enum from typing import IO, Any +from typing_extensions import Self if sys.version_info >= (3, 9): __all__ = ["InvalidFileException", "FMT_XML", "FMT_BINARY", "load", "dump", "loads", "dumps", "UID"] @@ -100,7 +101,7 @@ if sys.version_info >= (3, 8): data: int def __init__(self, data: int) -> None: ... def __index__(self) -> int: ... - def __reduce__(self: Self) -> tuple[type[Self], tuple[int]]: ... + def __reduce__(self) -> tuple[type[Self], tuple[int]]: ... def __eq__(self, other: object) -> bool: ... class InvalidFileException(ValueError): diff --git a/mypy/typeshed/stdlib/profile.pyi b/mypy/typeshed/stdlib/profile.pyi index 8d6e9b220587..6ae375004158 100644 --- a/mypy/typeshed/stdlib/profile.pyi +++ b/mypy/typeshed/stdlib/profile.pyi @@ -1,7 +1,7 @@ -from _typeshed import Self, StrOrBytesPath +from _typeshed import StrOrBytesPath from collections.abc import Callable from typing import Any, TypeVar -from typing_extensions import ParamSpec, TypeAlias +from typing_extensions import ParamSpec, Self, TypeAlias __all__ = ["run", "runctx", "Profile"] @@ -25,7 +25,7 @@ class Profile: def dump_stats(self, file: StrOrBytesPath) -> None: ... def create_stats(self) -> None: ... def snapshot_stats(self) -> None: ... - def run(self: Self, cmd: str) -> Self: ... - def runctx(self: Self, cmd: str, globals: dict[str, Any], locals: dict[str, Any]) -> Self: ... + def run(self, cmd: str) -> Self: ... + def runctx(self, cmd: str, globals: dict[str, Any], locals: dict[str, Any]) -> Self: ... def runcall(self, __func: Callable[_P, _T], *args: _P.args, **kw: _P.kwargs) -> _T: ... def calibrate(self, m: int, verbose: int = 0) -> float: ... diff --git a/mypy/typeshed/stdlib/pstats.pyi b/mypy/typeshed/stdlib/pstats.pyi index f4f331934565..5d25d1bb3641 100644 --- a/mypy/typeshed/stdlib/pstats.pyi +++ b/mypy/typeshed/stdlib/pstats.pyi @@ -1,11 +1,11 @@ import sys -from _typeshed import Self, StrOrBytesPath +from _typeshed import StrOrBytesPath from collections.abc import Iterable from cProfile import Profile as _cProfile from enum import Enum from profile import Profile from typing import IO, Any, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias if sys.version_info >= (3, 9): __all__ = ["Stats", "SortKey", "FunctionProfile", "StatsProfile"] @@ -47,7 +47,7 @@ _SortArgDict: TypeAlias = dict[str, tuple[tuple[tuple[int, int], ...], str]] class Stats: sort_arg_dict_default: _SortArgDict def __init__( - self: Self, + self, __arg: None | str | Profile | _cProfile = ..., *args: None | str | Profile | _cProfile | Self, stream: IO[Any] | None = None, @@ -55,24 +55,24 @@ class Stats: def init(self, arg: None | str | Profile | _cProfile) -> None: ... def load_stats(self, arg: None | str | Profile | _cProfile) -> None: ... def get_top_level_stats(self) -> None: ... - def add(self: Self, *arg_list: None | str | Profile | _cProfile | Self) -> Self: ... + def add(self, *arg_list: None | str | Profile | _cProfile | Self) -> Self: ... def dump_stats(self, filename: StrOrBytesPath) -> None: ... def get_sort_arg_defs(self) -> _SortArgDict: ... @overload - def sort_stats(self: Self, field: Literal[-1, 0, 1, 2]) -> Self: ... + def sort_stats(self, field: Literal[-1, 0, 1, 2]) -> Self: ... @overload - def sort_stats(self: Self, *field: str) -> Self: ... - def reverse_order(self: Self) -> Self: ... - def strip_dirs(self: Self) -> Self: ... + def sort_stats(self, *field: str) -> Self: ... + def reverse_order(self) -> Self: ... + def strip_dirs(self) -> Self: ... def calc_callees(self) -> None: ... def eval_print_amount(self, sel: _Selector, list: list[str], msg: str) -> tuple[list[str], str]: ... if sys.version_info >= (3, 9): def get_stats_profile(self) -> StatsProfile: ... def get_print_list(self, sel_list: Iterable[_Selector]) -> tuple[int, list[str]]: ... - def print_stats(self: Self, *amount: _Selector) -> Self: ... - def print_callees(self: Self, *amount: _Selector) -> Self: ... - def print_callers(self: Self, *amount: _Selector) -> Self: ... + def print_stats(self, *amount: _Selector) -> Self: ... + def print_callees(self, *amount: _Selector) -> Self: ... + def print_callers(self, *amount: _Selector) -> Self: ... def print_call_heading(self, name_size: int, column_title: str) -> None: ... def print_call_line(self, name_size: int, source: str, call_dict: dict[str, Any], arrow: str = "->") -> None: ... def print_title(self) -> None: ... diff --git a/mypy/typeshed/stdlib/pydoc.pyi b/mypy/typeshed/stdlib/pydoc.pyi index 9bcd8659fc8c..c6893d50c66a 100644 --- a/mypy/typeshed/stdlib/pydoc.pyi +++ b/mypy/typeshed/stdlib/pydoc.pyi @@ -6,16 +6,16 @@ from collections.abc import Callable, Container, Mapping, MutableMapping from reprlib import Repr from types import MethodType, ModuleType, TracebackType from typing import IO, Any, AnyStr, NoReturn, TypeVar -from typing_extensions import TypeGuard +from typing_extensions import Final, TypeGuard __all__ = ["help"] _T = TypeVar("_T") -__author__: str -__date__: str -__version__: str -__credits__: str +__author__: Final[str] +__date__: Final[str] +__version__: Final[str] +__credits__: Final[str] def pathdirs() -> list[str]: ... def getdoc(object: object) -> str: ... diff --git a/mypy/typeshed/stdlib/quopri.pyi b/mypy/typeshed/stdlib/quopri.pyi index 336f733f64c0..b652e139bd0e 100644 --- a/mypy/typeshed/stdlib/quopri.pyi +++ b/mypy/typeshed/stdlib/quopri.pyi @@ -5,7 +5,7 @@ __all__ = ["encode", "decode", "encodestring", "decodestring"] class _Input(SupportsRead[bytes], SupportsNoArgReadline[bytes], Protocol): ... -def encode(input: _Input, output: SupportsWrite[bytes], quotetabs: int, header: int = False) -> None: ... -def encodestring(s: ReadableBuffer, quotetabs: int = False, header: int = False) -> bytes: ... -def decode(input: _Input, output: SupportsWrite[bytes], header: int = False) -> None: ... -def decodestring(s: str | ReadableBuffer, header: int = False) -> bytes: ... +def encode(input: _Input, output: SupportsWrite[bytes], quotetabs: int, header: bool = False) -> None: ... +def encodestring(s: ReadableBuffer, quotetabs: bool = False, header: bool = False) -> bytes: ... +def decode(input: _Input, output: SupportsWrite[bytes], header: bool = False) -> None: ... +def decodestring(s: str | ReadableBuffer, header: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/re.pyi b/mypy/typeshed/stdlib/re.pyi index f45ac7383e5d..4e53141ade84 100644 --- a/mypy/typeshed/stdlib/re.pyi +++ b/mypy/typeshed/stdlib/re.pyi @@ -72,7 +72,7 @@ class Match(Generic[AnyStr]): def expand(self, template: AnyStr) -> AnyStr: ... # group() returns "AnyStr" or "AnyStr | None", depending on the pattern. @overload - def group(self, __group: Literal[0] = ...) -> AnyStr: ... + def group(self, __group: Literal[0] = 0) -> AnyStr: ... @overload def group(self, __group: str | int) -> AnyStr | Any: ... @overload diff --git a/mypy/typeshed/stdlib/runpy.pyi b/mypy/typeshed/stdlib/runpy.pyi index 7efc194c8c66..d4406ea4ac41 100644 --- a/mypy/typeshed/stdlib/runpy.pyi +++ b/mypy/typeshed/stdlib/runpy.pyi @@ -1,6 +1,7 @@ -from _typeshed import Self, Unused +from _typeshed import Unused from types import ModuleType from typing import Any +from typing_extensions import Self __all__ = ["run_module", "run_path"] @@ -8,7 +9,7 @@ class _TempModule: mod_name: str module: ModuleType def __init__(self, mod_name: str) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... class _ModifiedArgv0: diff --git a/mypy/typeshed/stdlib/select.pyi b/mypy/typeshed/stdlib/select.pyi index d02651320cf6..412fd71ee38d 100644 --- a/mypy/typeshed/stdlib/select.pyi +++ b/mypy/typeshed/stdlib/select.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import FileDescriptorLike, Self +from _typeshed import FileDescriptorLike from collections.abc import Iterable from types import TracebackType from typing import Any -from typing_extensions import final +from typing_extensions import Self, final if sys.platform != "win32": PIPE_BUF: int @@ -106,7 +106,7 @@ if sys.platform == "linux": @final class epoll: def __init__(self, sizehint: int = ..., flags: int = ...) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, __exc_type: type[BaseException] | None = None, diff --git a/mypy/typeshed/stdlib/selectors.pyi b/mypy/typeshed/stdlib/selectors.pyi index e15780fadee1..90a923f09355 100644 --- a/mypy/typeshed/stdlib/selectors.pyi +++ b/mypy/typeshed/stdlib/selectors.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import FileDescriptor, FileDescriptorLike, Self, Unused +from _typeshed import FileDescriptor, FileDescriptorLike, Unused from abc import ABCMeta, abstractmethod from collections.abc import Mapping from typing import Any, NamedTuple -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias _EventMask: TypeAlias = int @@ -28,7 +28,7 @@ class BaseSelector(metaclass=ABCMeta): def get_key(self, fileobj: FileDescriptorLike) -> SelectorKey: ... @abstractmethod def get_map(self) -> Mapping[FileDescriptorLike, SelectorKey]: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... class SelectSelector(BaseSelector): diff --git a/mypy/typeshed/stdlib/shelve.pyi b/mypy/typeshed/stdlib/shelve.pyi index d55e08bffa16..82d0b03f4049 100644 --- a/mypy/typeshed/stdlib/shelve.pyi +++ b/mypy/typeshed/stdlib/shelve.pyi @@ -1,8 +1,8 @@ -from _typeshed import Self from collections.abc import Iterator, MutableMapping from dbm import _TFlags from types import TracebackType from typing import Any, TypeVar, overload +from typing_extensions import Self __all__ = ["Shelf", "BsdDbShelf", "DbfilenameShelf", "open"] @@ -23,7 +23,7 @@ class Shelf(MutableMapping[str, _VT]): def __setitem__(self, key: str, value: _VT) -> None: ... def __delitem__(self, key: str) -> None: ... def __contains__(self, key: str) -> bool: ... # type: ignore[override] - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/shlex.pyi b/mypy/typeshed/stdlib/shlex.pyi index 9a578d186be8..fa04932db676 100644 --- a/mypy/typeshed/stdlib/shlex.pyi +++ b/mypy/typeshed/stdlib/shlex.pyi @@ -1,7 +1,7 @@ import sys -from _typeshed import Self from collections.abc import Iterable from typing import TextIO +from typing_extensions import Self if sys.version_info >= (3, 8): __all__ = ["shlex", "split", "quote", "join"] @@ -46,5 +46,5 @@ class shlex(Iterable[str]): def push_source(self, newstream: str | TextIO, newfile: str | None = None) -> None: ... def pop_source(self) -> None: ... def error_leader(self, infile: str | None = None, lineno: int | None = None) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> str: ... diff --git a/mypy/typeshed/stdlib/signal.pyi b/mypy/typeshed/stdlib/signal.pyi index e0d7364c6b4e..e411d47016b6 100644 --- a/mypy/typeshed/stdlib/signal.pyi +++ b/mypy/typeshed/stdlib/signal.pyi @@ -3,7 +3,7 @@ from _typeshed import structseq from collections.abc import Callable, Iterable from enum import IntEnum from types import FrameType -from typing import Any, Union +from typing import Any from typing_extensions import Final, Never, TypeAlias, final NSIG: int @@ -62,7 +62,7 @@ SIG_DFL: Handlers SIG_IGN: Handlers _SIGNUM: TypeAlias = int | Signals -_HANDLER: TypeAlias = Union[Callable[[int, FrameType | None], Any], int, Handlers, None] +_HANDLER: TypeAlias = Callable[[int, FrameType | None], Any] | int | Handlers | None def default_int_handler(__signalnum: int, __frame: FrameType | None) -> Never: ... @@ -113,7 +113,7 @@ else: SIGXCPU: Signals SIGXFSZ: Signals - class ItimerError(IOError): ... + class ItimerError(OSError): ... ITIMER_PROF: int ITIMER_REAL: int ITIMER_VIRTUAL: int @@ -178,4 +178,4 @@ def set_wakeup_fd(fd: int, *, warn_on_full_buffer: bool = ...) -> int: ... if sys.version_info >= (3, 9): if sys.platform == "linux": - def pidfd_send_signal(__pidfd: int, __sig: int, __siginfo: None = ..., __flags: int = ...) -> None: ... + def pidfd_send_signal(__pidfd: int, __sig: int, __siginfo: None = None, __flags: int = ...) -> None: ... diff --git a/mypy/typeshed/stdlib/smtplib.pyi b/mypy/typeshed/stdlib/smtplib.pyi index d0d674242bf8..0d7595fc1d6d 100644 --- a/mypy/typeshed/stdlib/smtplib.pyi +++ b/mypy/typeshed/stdlib/smtplib.pyi @@ -1,6 +1,6 @@ import sys from _socket import _Address as _SourceAddress -from _typeshed import ReadableBuffer, Self, _BufferWithLen +from _typeshed import ReadableBuffer, _BufferWithLen from collections.abc import Sequence from email.message import Message as _Message from re import Pattern @@ -8,7 +8,7 @@ from socket import socket from ssl import SSLContext from types import TracebackType from typing import Any, Protocol, overload -from typing_extensions import TypeAlias +from typing_extensions import Self, TypeAlias __all__ = [ "SMTPException", @@ -68,7 +68,7 @@ def quotedata(data: str) -> str: ... class _AuthObject(Protocol): @overload - def __call__(self, challenge: None = ...) -> str | None: ... + def __call__(self, challenge: None = None) -> str | None: ... @overload def __call__(self, challenge: bytes) -> str: ... @@ -95,7 +95,7 @@ class SMTP: timeout: float = ..., source_address: _SourceAddress | None = None, ) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, tb: TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/socket.pyi b/mypy/typeshed/stdlib/socket.pyi index 4481f398867c..dbc1d46ec1d4 100644 --- a/mypy/typeshed/stdlib/socket.pyi +++ b/mypy/typeshed/stdlib/socket.pyi @@ -112,12 +112,12 @@ from _socket import ( setdefaulttimeout as setdefaulttimeout, timeout as timeout, ) -from _typeshed import ReadableBuffer, Self, Unused, WriteableBuffer +from _typeshed import ReadableBuffer, Unused, WriteableBuffer from collections.abc import Iterable from enum import IntEnum, IntFlag from io import BufferedReader, BufferedRWPair, BufferedWriter, IOBase, RawIOBase, TextIOWrapper from typing import Any, Protocol, overload -from typing_extensions import Literal +from typing_extensions import Literal, Self if sys.platform != "darwin" or sys.version_info >= (3, 9): from _socket import ( @@ -657,9 +657,9 @@ class socket(_socket.socket): def __init__( self, family: AddressFamily | int = -1, type: SocketKind | int = -1, proto: int = -1, fileno: int | None = None ) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... - def dup(self: Self) -> Self: ... # noqa: F811 + def dup(self) -> Self: ... # noqa: F811 def accept(self) -> tuple[socket, _RetAddress]: ... # Note that the makefile's documented windows-specific behavior is not represented # mode strings with duplicates are intentionally excluded diff --git a/mypy/typeshed/stdlib/socketserver.pyi b/mypy/typeshed/stdlib/socketserver.pyi index b35f1553fb44..3f0bb0eea0ce 100644 --- a/mypy/typeshed/stdlib/socketserver.pyi +++ b/mypy/typeshed/stdlib/socketserver.pyi @@ -1,11 +1,11 @@ import sys import types from _socket import _Address, _RetAddress -from _typeshed import ReadableBuffer, Self +from _typeshed import ReadableBuffer from collections.abc import Callable from socket import socket as _socket -from typing import Any, BinaryIO, ClassVar, Union -from typing_extensions import TypeAlias +from typing import Any, BinaryIO, ClassVar +from typing_extensions import Self, TypeAlias __all__ = [ "BaseServer", @@ -29,7 +29,7 @@ if sys.platform != "win32": "UnixStreamServer", ] -_RequestType: TypeAlias = Union[_socket, tuple[bytes, _socket]] +_RequestType: TypeAlias = _socket | tuple[bytes, _socket] _AfUnixAddress: TypeAlias = str | ReadableBuffer # adddress acceptable for an AF_UNIX socket _AfInetAddress: TypeAlias = tuple[str | bytes | bytearray, int] # address acceptable for an AF_INET socket @@ -43,13 +43,13 @@ class BaseServer: socket_type: int timeout: float | None def __init__( - self: Self, server_address: _Address, RequestHandlerClass: Callable[[Any, _RetAddress, Self], BaseRequestHandler] + self, server_address: _Address, RequestHandlerClass: Callable[[Any, _RetAddress, Self], BaseRequestHandler] ) -> None: ... # It is not actually a `@property`, but we need a `Self` type: @property - def RequestHandlerClass(self: Self) -> Callable[[Any, _RetAddress, Self], BaseRequestHandler]: ... + def RequestHandlerClass(self) -> Callable[[Any, _RetAddress, Self], BaseRequestHandler]: ... @RequestHandlerClass.setter - def RequestHandlerClass(self: Self, val: Callable[[Any, _RetAddress, Self], BaseRequestHandler]) -> None: ... + def RequestHandlerClass(self, val: Callable[[Any, _RetAddress, Self], BaseRequestHandler]) -> None: ... def fileno(self) -> int: ... def handle_request(self) -> None: ... def serve_forever(self, poll_interval: float = 0.5) -> None: ... @@ -63,7 +63,7 @@ class BaseServer: def server_activate(self) -> None: ... def server_bind(self) -> None: ... def verify_request(self, request: _RequestType, client_address: _RetAddress) -> bool: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... @@ -76,7 +76,7 @@ class TCPServer(BaseServer): allow_reuse_port: bool server_address: _AfInetAddress # type: ignore[assignment] def __init__( - self: Self, + self, server_address: _AfInetAddress, RequestHandlerClass: Callable[[Any, _RetAddress, Self], BaseRequestHandler], bind_and_activate: bool = True, @@ -91,7 +91,7 @@ if sys.platform != "win32": class UnixStreamServer(BaseServer): server_address: _AfUnixAddress # type: ignore[assignment] def __init__( - self: Self, + self, server_address: _AfUnixAddress, RequestHandlerClass: Callable[[Any, _RetAddress, Self], BaseRequestHandler], bind_and_activate: bool = True, @@ -100,7 +100,7 @@ if sys.platform != "win32": class UnixDatagramServer(BaseServer): server_address: _AfUnixAddress # type: ignore[assignment] def __init__( - self: Self, + self, server_address: _AfUnixAddress, RequestHandlerClass: Callable[[Any, _RetAddress, Self], BaseRequestHandler], bind_and_activate: bool = True, diff --git a/mypy/typeshed/stdlib/sqlite3/dbapi2.pyi b/mypy/typeshed/stdlib/sqlite3/dbapi2.pyi index 01274d6e2a60..26188445547e 100644 --- a/mypy/typeshed/stdlib/sqlite3/dbapi2.pyi +++ b/mypy/typeshed/stdlib/sqlite3/dbapi2.pyi @@ -1,11 +1,11 @@ import sqlite3 import sys -from _typeshed import Incomplete, ReadableBuffer, Self, StrOrBytesPath, SupportsLenAndGetItem, Unused +from _typeshed import Incomplete, ReadableBuffer, StrOrBytesPath, SupportsLenAndGetItem, Unused from collections.abc import Callable, Generator, Iterable, Iterator, Mapping from datetime import date, datetime, time from types import TracebackType from typing import Any, Protocol, TypeVar, overload -from typing_extensions import Literal, SupportsIndex, TypeAlias, final +from typing_extensions import Literal, Self, SupportsIndex, TypeAlias, final _T = TypeVar("_T") _CursorT = TypeVar("_CursorT", bound=Cursor) @@ -324,7 +324,7 @@ class Connection: def create_function(self, name: str, num_params: int, func: Callable[..., _SqliteData] | None) -> None: ... @overload - def cursor(self, cursorClass: None = ...) -> Cursor: ... + def cursor(self, cursorClass: None = None) -> Cursor: ... @overload def cursor(self, cursorClass: Callable[[], _CursorT]) -> _CursorT: ... def execute(self, sql: str, parameters: _Parameters = ...) -> Cursor: ... @@ -358,7 +358,7 @@ class Connection: def deserialize(self, __data: ReadableBuffer, *, name: str = "main") -> None: ... def __call__(self, __sql: str) -> _Statement: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, __type: type[BaseException] | None, __value: BaseException | None, __traceback: TracebackType | None ) -> Literal[False]: ... @@ -377,8 +377,8 @@ class Cursor(Iterator[Any]): def rowcount(self) -> int: ... def __init__(self, __cursor: Connection) -> None: ... def close(self) -> None: ... - def execute(self: Self, __sql: str, __parameters: _Parameters = ...) -> Self: ... - def executemany(self: Self, __sql: str, __seq_of_parameters: Iterable[_Parameters]) -> Self: ... + def execute(self, __sql: str, __parameters: _Parameters = ...) -> Self: ... + def executemany(self, __sql: str, __seq_of_parameters: Iterable[_Parameters]) -> Self: ... def executescript(self, __sql_script: str) -> Cursor: ... def fetchall(self) -> list[Any]: ... def fetchmany(self, size: int | None = 1) -> list[Any]: ... @@ -387,7 +387,7 @@ class Cursor(Iterator[Any]): def fetchone(self) -> Any: ... def setinputsizes(self, __sizes: Unused) -> None: ... # does nothing def setoutputsize(self, __size: Unused, __column: Unused = None) -> None: ... # does nothing - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> Any: ... class DataError(DatabaseError): ... @@ -452,7 +452,7 @@ if sys.version_info >= (3, 11): # whence must be one of os.SEEK_SET, os.SEEK_CUR, os.SEEK_END def seek(self, __offset: int, __origin: int = 0) -> None: ... def __len__(self) -> int: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, __typ: object, __val: object, __tb: object) -> Literal[False]: ... def __getitem__(self, __item: SupportsIndex | slice) -> int: ... def __setitem__(self, __item: SupportsIndex | slice, __value: int) -> None: ... diff --git a/mypy/typeshed/stdlib/sre_constants.pyi b/mypy/typeshed/stdlib/sre_constants.pyi index fe25eaf9728e..d522372c438c 100644 --- a/mypy/typeshed/stdlib/sre_constants.pyi +++ b/mypy/typeshed/stdlib/sre_constants.pyi @@ -1,6 +1,6 @@ import sys -from _typeshed import Self from typing import Any +from typing_extensions import Self MAXGROUPS: int @@ -16,7 +16,7 @@ class error(Exception): class _NamedIntConstant(int): name: Any - def __new__(cls: type[Self], value: int, name: str) -> Self: ... + def __new__(cls, value: int, name: str) -> Self: ... MAXREPEAT: _NamedIntConstant OPCODES: list[_NamedIntConstant] diff --git a/mypy/typeshed/stdlib/ssl.pyi b/mypy/typeshed/stdlib/ssl.pyi index f8b97fb60eb7..bbf8a4c6d65a 100644 --- a/mypy/typeshed/stdlib/ssl.pyi +++ b/mypy/typeshed/stdlib/ssl.pyi @@ -1,17 +1,17 @@ import enum import socket import sys -from _typeshed import ReadableBuffer, Self, StrOrBytesPath, WriteableBuffer +from _typeshed import ReadableBuffer, StrOrBytesPath, WriteableBuffer from collections.abc import Callable, Iterable -from typing import Any, NamedTuple, Union, overload -from typing_extensions import Literal, TypeAlias, TypedDict, final +from typing import Any, NamedTuple, overload +from typing_extensions import Literal, Self, TypeAlias, TypedDict, final _PCTRTT: TypeAlias = tuple[tuple[str, str], ...] _PCTRTTT: TypeAlias = tuple[_PCTRTT, ...] _PeerCertRetDictType: TypeAlias = dict[str, str | _PCTRTTT | _PCTRTT] _PeerCertRetType: TypeAlias = _PeerCertRetDictType | bytes | None _EnumRetType: TypeAlias = list[tuple[bytes, str, set[str] | bool]] -_PasswordType: TypeAlias = Union[Callable[[], str | bytes | bytearray], str, bytes, bytearray] +_PasswordType: TypeAlias = Callable[[], str | bytes | bytearray] | str | bytes | bytearray _SrvnmeCbType: TypeAlias = Callable[[SSLSocket | SSLObject, str | None, SSLSocket], int | None] @@ -297,9 +297,9 @@ class _ASN1Object(NamedTuple): longname: str oid: str @classmethod - def fromnid(cls: type[Self], nid: int) -> Self: ... + def fromnid(cls, nid: int) -> Self: ... @classmethod - def fromname(cls: type[Self], name: str) -> Self: ... + def fromname(cls, name: str) -> Self: ... class Purpose(_ASN1Object, enum.Enum): SERVER_AUTH: _ASN1Object @@ -383,9 +383,9 @@ class SSLContext: if sys.version_info >= (3, 10): # Using the default (None) for the `protocol` parameter is deprecated, # but there isn't a good way of marking that in the stub unless/until PEP 702 is accepted - def __new__(cls: type[Self], protocol: int | None = None, *args: Any, **kwargs: Any) -> Self: ... + def __new__(cls, protocol: int | None = None, *args: Any, **kwargs: Any) -> Self: ... else: - def __new__(cls: type[Self], protocol: int = ..., *args: Any, **kwargs: Any) -> Self: ... + def __new__(cls, protocol: int = ..., *args: Any, **kwargs: Any) -> Self: ... def cert_store_stats(self) -> dict[str, int]: ... def load_cert_chain( diff --git a/mypy/typeshed/stdlib/statistics.pyi b/mypy/typeshed/stdlib/statistics.pyi index 4ef950b9b4de..1358b1f90d7d 100644 --- a/mypy/typeshed/stdlib/statistics.pyi +++ b/mypy/typeshed/stdlib/statistics.pyi @@ -1,10 +1,10 @@ import sys -from _typeshed import Self, SupportsRichComparisonT +from _typeshed import SupportsRichComparisonT from collections.abc import Hashable, Iterable, Sequence from decimal import Decimal from fractions import Fraction from typing import Any, NamedTuple, SupportsFloat, TypeVar -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias __all__ = [ "StatisticsError", @@ -93,7 +93,7 @@ if sys.version_info >= (3, 8): @property def variance(self) -> float: ... @classmethod - def from_samples(cls: type[Self], data: Iterable[SupportsFloat]) -> Self: ... + def from_samples(cls, data: Iterable[SupportsFloat]) -> Self: ... def samples(self, n: int, *, seed: Any | None = None) -> list[float]: ... def pdf(self, x: float) -> float: ... def cdf(self, x: float) -> float: ... diff --git a/mypy/typeshed/stdlib/subprocess.pyi b/mypy/typeshed/stdlib/subprocess.pyi index 35a7b7e34f6b..3940fad7b915 100644 --- a/mypy/typeshed/stdlib/subprocess.pyi +++ b/mypy/typeshed/stdlib/subprocess.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import ReadableBuffer, Self, StrOrBytesPath +from _typeshed import ReadableBuffer, StrOrBytesPath from collections.abc import Callable, Collection, Iterable, Mapping, Sequence from types import TracebackType from typing import IO, Any, AnyStr, Generic, TypeVar, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias @@ -257,8 +257,8 @@ if sys.version_info >= (3, 11): *, capture_output: bool = False, check: bool = False, - encoding: None = ..., - errors: None = ..., + encoding: None = None, + errors: None = None, input: ReadableBuffer | None = None, text: Literal[None, False] = ..., timeout: float | None = None, @@ -461,8 +461,8 @@ elif sys.version_info >= (3, 10): *, capture_output: bool = False, check: bool = False, - encoding: None = ..., - errors: None = ..., + encoding: None = None, + errors: None = None, input: ReadableBuffer | None = None, text: Literal[None, False] = ..., timeout: float | None = None, @@ -659,8 +659,8 @@ elif sys.version_info >= (3, 9): *, capture_output: bool = False, check: bool = False, - encoding: None = ..., - errors: None = ..., + encoding: None = None, + errors: None = None, input: ReadableBuffer | None = None, text: Literal[None, False] = ..., timeout: float | None = None, @@ -838,8 +838,8 @@ else: *, capture_output: bool = False, check: bool = False, - encoding: None = ..., - errors: None = ..., + encoding: None = None, + errors: None = None, input: ReadableBuffer | None = None, text: Literal[None, False] = ..., timeout: float | None = None, @@ -994,7 +994,7 @@ if sys.version_info >= (3, 11): def check_call( args: _CMD, bufsize: int = ..., - executable: StrOrBytesPath = ..., + executable: StrOrBytesPath | None = None, stdin: _FILE = ..., stdout: _FILE = ..., stderr: _FILE = ..., @@ -1025,7 +1025,7 @@ elif sys.version_info >= (3, 10): def check_call( args: _CMD, bufsize: int = ..., - executable: StrOrBytesPath = ..., + executable: StrOrBytesPath | None = None, stdin: _FILE = ..., stdout: _FILE = ..., stderr: _FILE = ..., @@ -1055,7 +1055,7 @@ elif sys.version_info >= (3, 9): def check_call( args: _CMD, bufsize: int = ..., - executable: StrOrBytesPath = ..., + executable: StrOrBytesPath | None = None, stdin: _FILE = ..., stdout: _FILE = ..., stderr: _FILE = ..., @@ -1083,7 +1083,7 @@ else: def check_call( args: _CMD, bufsize: int = ..., - executable: StrOrBytesPath = ..., + executable: StrOrBytesPath | None = None, stdin: _FILE = ..., stdout: _FILE = ..., stderr: _FILE = ..., @@ -1251,8 +1251,8 @@ if sys.version_info >= (3, 11): *, timeout: float | None = None, input: _InputString | None = ..., - encoding: None = ..., - errors: None = ..., + encoding: None = None, + errors: None = None, text: Literal[None, False] = ..., user: str | int | None = ..., group: str | int | None = ..., @@ -1437,8 +1437,8 @@ elif sys.version_info >= (3, 10): *, timeout: float | None = None, input: _InputString | None = ..., - encoding: None = ..., - errors: None = ..., + encoding: None = None, + errors: None = None, text: Literal[None, False] = ..., user: str | int | None = ..., group: str | int | None = ..., @@ -1617,8 +1617,8 @@ elif sys.version_info >= (3, 9): *, timeout: float | None = None, input: _InputString | None = ..., - encoding: None = ..., - errors: None = ..., + encoding: None = None, + errors: None = None, text: Literal[None, False] = ..., user: str | int | None = ..., group: str | int | None = ..., @@ -1778,8 +1778,8 @@ else: *, timeout: float | None = None, input: _InputString | None = ..., - encoding: None = ..., - errors: None = ..., + encoding: None = None, + errors: None = None, text: Literal[None, False] = ..., ) -> bytes: ... @overload @@ -2560,7 +2560,7 @@ class Popen(Generic[AnyStr]): def send_signal(self, sig: int) -> None: ... def terminate(self) -> None: ... def kill(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/sunau.pyi b/mypy/typeshed/stdlib/sunau.pyi index 7702443b0c1c..6109b368c01a 100644 --- a/mypy/typeshed/stdlib/sunau.pyi +++ b/mypy/typeshed/stdlib/sunau.pyi @@ -1,7 +1,7 @@ import sys -from _typeshed import Self, Unused +from _typeshed import Unused from typing import IO, Any, NamedTuple, NoReturn, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias _File: TypeAlias = str | IO[bytes] @@ -32,7 +32,7 @@ class _sunau_params(NamedTuple): class Au_read: def __init__(self, f: _File) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... def getfp(self) -> IO[bytes] | None: ... def rewind(self) -> None: ... @@ -52,7 +52,7 @@ class Au_read: class Au_write: def __init__(self, f: _File) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... def setnchannels(self, nchannels: int) -> None: ... def getnchannels(self) -> int: ... diff --git a/mypy/typeshed/stdlib/sys.pyi b/mypy/typeshed/stdlib/sys.pyi index 725f66794cf6..e12881599b4a 100644 --- a/mypy/typeshed/stdlib/sys.pyi +++ b/mypy/typeshed/stdlib/sys.pyi @@ -7,7 +7,7 @@ from importlib.machinery import ModuleSpec from io import TextIOWrapper from types import FrameType, ModuleType, TracebackType from typing import Any, NoReturn, Protocol, TextIO, TypeVar, overload -from typing_extensions import Literal, TypeAlias, final +from typing_extensions import Final, Literal, TypeAlias, final _T = TypeVar("_T") @@ -62,9 +62,10 @@ stdout: TextIO stderr: TextIO if sys.version_info >= (3, 10): stdlib_module_names: frozenset[str] -__stdin__: TextIOWrapper -__stdout__: TextIOWrapper -__stderr__: TextIOWrapper + +__stdin__: Final[TextIOWrapper] # Contains the original value of stdin +__stdout__: Final[TextIOWrapper] # Contains the original value of stdout +__stderr__: Final[TextIOWrapper] # Contains the original value of stderr tracebacklimit: int version: str api_version: int @@ -277,11 +278,10 @@ if sys.platform == "win32": def intern(__string: str) -> str: ... def is_finalizing() -> bool: ... - -__breakpointhook__: Any # contains the original value of breakpointhook - def breakpointhook(*args: Any, **kwargs: Any) -> Any: ... +__breakpointhook__ = breakpointhook # Contains the original value of breakpointhook + if sys.platform != "win32": def setdlopenflags(__flags: int) -> None: ... diff --git a/mypy/typeshed/stdlib/tarfile.pyi b/mypy/typeshed/stdlib/tarfile.pyi index 0aca7956a580..5cf1d55cac63 100644 --- a/mypy/typeshed/stdlib/tarfile.pyi +++ b/mypy/typeshed/stdlib/tarfile.pyi @@ -1,13 +1,13 @@ import bz2 import io import sys -from _typeshed import Self, StrOrBytesPath, StrPath -from builtins import list as _list, type as Type # aliases to avoid name clashes with fields named "type" or "list" +from _typeshed import StrOrBytesPath, StrPath +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 from types import TracebackType from typing import IO, ClassVar, Protocol, overload -from typing_extensions import Literal +from typing_extensions import Literal, Self __all__ = [ "TarFile", @@ -141,14 +141,14 @@ class TarFile: errorlevel: int | None = None, copybufsize: int | None = None, # undocumented ) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... def __iter__(self) -> Iterator[TarInfo]: ... @classmethod def open( - cls: type[Self], + cls, name: StrOrBytesPath | None = None, mode: str = "r", fileobj: IO[bytes] | None = None, # depends on mode @@ -166,7 +166,7 @@ class TarFile: ) -> Self: ... @classmethod def taropen( - cls: type[Self], + cls, name: StrOrBytesPath | None, mode: Literal["r", "a", "w", "x"] = "r", fileobj: _Fileobj | None = None, @@ -184,7 +184,7 @@ class TarFile: @overload @classmethod def gzopen( - cls: type[Self], + cls, name: StrOrBytesPath | None, mode: Literal["r"] = "r", fileobj: _GzipReadableFileobj | None = None, @@ -202,7 +202,7 @@ class TarFile: @overload @classmethod def gzopen( - cls: type[Self], + cls, name: StrOrBytesPath | None, mode: Literal["w", "x"], fileobj: _GzipWritableFileobj | None = None, @@ -220,7 +220,7 @@ class TarFile: @overload @classmethod def bz2open( - cls: type[Self], + cls, name: StrOrBytesPath | None, mode: Literal["w", "x"], fileobj: _Bz2WritableFileobj | None = None, @@ -238,7 +238,7 @@ class TarFile: @overload @classmethod def bz2open( - cls: type[Self], + cls, name: StrOrBytesPath | None, mode: Literal["r"] = "r", fileobj: _Bz2ReadableFileobj | None = None, @@ -255,7 +255,7 @@ class TarFile: ) -> Self: ... @classmethod def xzopen( - cls: type[Self], + cls, name: StrOrBytesPath | None, mode: Literal["r", "w", "x"] = "r", fileobj: IO[bytes] | None = None, @@ -346,9 +346,9 @@ class TarInfo: pax_headers: Mapping[str, str] def __init__(self, name: str = "") -> None: ... @classmethod - def frombuf(cls: Type[Self], buf: bytes | bytearray, encoding: str, errors: str) -> Self: ... + def frombuf(cls, buf: bytes | bytearray, encoding: str, errors: str) -> Self: ... @classmethod - def fromtarfile(cls: Type[Self], tarfile: TarFile) -> Self: ... + def fromtarfile(cls, tarfile: TarFile) -> Self: ... @property def linkpath(self) -> str: ... @linkpath.setter diff --git a/mypy/typeshed/stdlib/telnetlib.pyi b/mypy/typeshed/stdlib/telnetlib.pyi index bcf9ef3693b2..10f6e4930f75 100644 --- a/mypy/typeshed/stdlib/telnetlib.pyi +++ b/mypy/typeshed/stdlib/telnetlib.pyi @@ -1,9 +1,9 @@ import socket -from _typeshed import Self from collections.abc import Callable, Sequence from re import Match, Pattern from types import TracebackType from typing import Any +from typing_extensions import Self __all__ = ["Telnet"] @@ -115,7 +115,7 @@ class Telnet: def expect( self, list: Sequence[Pattern[bytes] | bytes], timeout: float | None = None ) -> tuple[int, Match[bytes] | None, bytes]: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/tempfile.pyi b/mypy/typeshed/stdlib/tempfile.pyi index 9dc23be2557f..dbff6d632d02 100644 --- a/mypy/typeshed/stdlib/tempfile.pyi +++ b/mypy/typeshed/stdlib/tempfile.pyi @@ -1,10 +1,10 @@ import io import sys -from _typeshed import BytesPath, GenericPath, Self, StrPath, WriteableBuffer +from _typeshed import BytesPath, GenericPath, StrPath, WriteableBuffer from collections.abc import Iterable, Iterator from types import TracebackType from typing import IO, Any, AnyStr, Generic, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias if sys.version_info >= (3, 9): from types import GenericAlias @@ -186,7 +186,7 @@ class _TemporaryFileWrapper(Generic[AnyStr], IO[AnyStr]): name: str delete: bool def __init__(self, file: IO[AnyStr], name: str, delete: bool = True) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, exc: type[BaseException] | None, value: BaseException | None, tb: TracebackType | None) -> None: ... def __getattr__(self, name: str) -> Any: ... def close(self) -> None: ... @@ -369,7 +369,7 @@ class SpooledTemporaryFile(IO[AnyStr], _SpooledTemporaryFileBase): ) -> None: ... def rollover(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, exc: type[BaseException] | None, value: BaseException | None, tb: TracebackType | None) -> None: ... # These methods are copied from the abstract methods of IO, because # SpooledTemporaryFile implements IO. diff --git a/mypy/typeshed/stdlib/tkinter/__init__.pyi b/mypy/typeshed/stdlib/tkinter/__init__.pyi index fdacf0097008..1d30e4b73c23 100644 --- a/mypy/typeshed/stdlib/tkinter/__init__.pyi +++ b/mypy/typeshed/stdlib/tkinter/__init__.pyi @@ -6,7 +6,7 @@ from enum import Enum from tkinter.constants import * from tkinter.font import _FontDescription from types import TracebackType -from typing import Any, Generic, NamedTuple, Protocol, TypeVar, Union, overload +from typing import Any, Generic, NamedTuple, Protocol, TypeVar, overload from typing_extensions import Literal, TypeAlias, TypedDict if sys.version_info >= (3, 9): @@ -179,7 +179,7 @@ _CanvasItemId: TypeAlias = int _Color: TypeAlias = str # typically '#rrggbb', '#rgb' or color names. _Compound: TypeAlias = Literal["top", "left", "center", "right", "bottom", "none"] # -compound in manual page named 'options' # manual page: Tk_GetCursor -_Cursor: TypeAlias = Union[str, tuple[str], tuple[str, str], tuple[str, str, str], tuple[str, str, str, str]] +_Cursor: TypeAlias = str | tuple[str] | tuple[str, str] | tuple[str, str, str] | tuple[str, str, str, str] # example when it's sequence: entry['invalidcommand'] = [entry.register(print), '%P'] _EntryValidateCommand: TypeAlias = str | list[str] | tuple[str, ...] | Callable[[], bool] _GridIndex: TypeAlias = int | str @@ -188,7 +188,7 @@ _Relief: TypeAlias = Literal["raised", "sunken", "flat", "ridge", "solid", "groo _ScreenUnits: TypeAlias = str | float # Often the right type instead of int. Manual page: Tk_GetPixels # -xscrollcommand and -yscrollcommand in 'options' manual page _XYScrollCommand: TypeAlias = str | Callable[[float, float], object] -_TakeFocusValue: TypeAlias = Union[int, Literal[""], Callable[[str], bool | None]] # -takefocus in manual page named 'options' +_TakeFocusValue: TypeAlias = int | Literal[""] | Callable[[str], bool | None] # -takefocus in manual page named 'options' if sys.version_info >= (3, 11): class _VersionInfoType(NamedTuple): @@ -421,7 +421,7 @@ class Misc: def winfo_viewable(self) -> bool: ... def winfo_visual(self) -> str: ... def winfo_visualid(self) -> str: ... - def winfo_visualsavailable(self, includeids: int = False) -> list[tuple[str, int]]: ... + def winfo_visualsavailable(self, includeids: bool = False) -> list[tuple[str, int]]: ... def winfo_vrootheight(self) -> int: ... def winfo_vrootwidth(self) -> int: ... def winfo_vrootx(self) -> int: ... diff --git a/mypy/typeshed/stdlib/tkinter/ttk.pyi b/mypy/typeshed/stdlib/tkinter/ttk.pyi index bd477535f41f..61ebc0e2734f 100644 --- a/mypy/typeshed/stdlib/tkinter/ttk.pyi +++ b/mypy/typeshed/stdlib/tkinter/ttk.pyi @@ -4,7 +4,7 @@ import tkinter from _typeshed import Incomplete from collections.abc import Callable from tkinter.font import _FontDescription -from typing import Any, Union, overload +from typing import Any, overload from typing_extensions import Literal, TypeAlias, TypedDict __all__ = [ @@ -38,13 +38,13 @@ __all__ = [ def tclobjs_to_py(adict: dict[Any, Any]) -> dict[Any, Any]: ... def setup_master(master: Incomplete | None = None): ... -_Padding: TypeAlias = Union[ - tkinter._ScreenUnits, - tuple[tkinter._ScreenUnits], - tuple[tkinter._ScreenUnits, tkinter._ScreenUnits], - tuple[tkinter._ScreenUnits, tkinter._ScreenUnits, tkinter._ScreenUnits], - tuple[tkinter._ScreenUnits, tkinter._ScreenUnits, tkinter._ScreenUnits, tkinter._ScreenUnits], -] +_Padding: TypeAlias = ( + tkinter._ScreenUnits + | tuple[tkinter._ScreenUnits] + | tuple[tkinter._ScreenUnits, tkinter._ScreenUnits] + | tuple[tkinter._ScreenUnits, tkinter._ScreenUnits, tkinter._ScreenUnits] + | tuple[tkinter._ScreenUnits, tkinter._ScreenUnits, tkinter._ScreenUnits, tkinter._ScreenUnits] +) # from ttk_widget (aka ttk::widget) manual page, differs from tkinter._Compound _TtkCompound: TypeAlias = Literal["text", "image", tkinter._Compound] diff --git a/mypy/typeshed/stdlib/traceback.pyi b/mypy/typeshed/stdlib/traceback.pyi index cdda50c0a1b3..4483a8c2a1b0 100644 --- a/mypy/typeshed/stdlib/traceback.pyi +++ b/mypy/typeshed/stdlib/traceback.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import Self, SupportsWrite +from _typeshed import SupportsWrite from collections.abc import Generator, Iterable, Iterator, Mapping from types import FrameType, TracebackType from typing import Any, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias __all__ = [ "extract_stack", @@ -129,7 +129,7 @@ class TracebackException: ) -> None: ... @classmethod def from_exception( - cls: type[Self], + cls, exc: BaseException, *, limit: int | None = ..., @@ -154,7 +154,7 @@ class TracebackException: ) -> None: ... @classmethod def from_exception( - cls: type[Self], + cls, exc: BaseException, *, limit: int | None = ..., @@ -176,7 +176,7 @@ class TracebackException: ) -> None: ... @classmethod def from_exception( - cls: type[Self], exc: BaseException, *, limit: int | None = ..., lookup_lines: bool = ..., capture_locals: bool = ... + cls, exc: BaseException, *, limit: int | None = ..., lookup_lines: bool = ..., capture_locals: bool = ... ) -> Self: ... def __eq__(self, other: object) -> bool: ... diff --git a/mypy/typeshed/stdlib/tracemalloc.pyi b/mypy/typeshed/stdlib/tracemalloc.pyi index d7214de285f8..3dc8b8603fe5 100644 --- a/mypy/typeshed/stdlib/tracemalloc.pyi +++ b/mypy/typeshed/stdlib/tracemalloc.pyi @@ -1,7 +1,7 @@ import sys from _tracemalloc import * from collections.abc import Sequence -from typing import Any, Union, overload +from typing import Any, overload from typing_extensions import SupportsIndex, TypeAlias def get_object_traceback(obj: object) -> Traceback | None: ... @@ -67,7 +67,7 @@ class Frame: def __le__(self, other: Frame, NotImplemented: Any = ...) -> bool: ... if sys.version_info >= (3, 9): - _TraceTuple: TypeAlias = Union[tuple[int, int, Sequence[_FrameTuple], int | None], tuple[int, int, Sequence[_FrameTuple]]] + _TraceTuple: TypeAlias = tuple[int, int, Sequence[_FrameTuple], int | None] | tuple[int, int, Sequence[_FrameTuple]] else: _TraceTuple: TypeAlias = tuple[int, int, Sequence[_FrameTuple]] diff --git a/mypy/typeshed/stdlib/turtle.pyi b/mypy/typeshed/stdlib/turtle.pyi index 1259ca6fb4cc..8017c8290fb9 100644 --- a/mypy/typeshed/stdlib/turtle.pyi +++ b/mypy/typeshed/stdlib/turtle.pyi @@ -1,8 +1,7 @@ -from _typeshed import Self from collections.abc import Callable, Sequence from tkinter import Canvas, Frame, Misc, PhotoImage, Scrollbar -from typing import Any, ClassVar, Union, overload -from typing_extensions import TypeAlias +from typing import Any, ClassVar, overload +from typing_extensions import Self, TypeAlias __all__ = [ "ScrolledCanvas", @@ -133,7 +132,7 @@ __all__ = [ # alias we use for return types. Really, these two aliases should be the # same, but as per the "no union returns" typeshed policy, we'll return # Any instead. -_Color: TypeAlias = Union[str, tuple[float, float, float]] +_Color: TypeAlias = str | tuple[float, float, float] _AnyColor: TypeAlias = Any # TODO: Replace this with a TypedDict once it becomes standardized. @@ -143,7 +142,7 @@ _Speed: TypeAlias = str | float _PolygonCoords: TypeAlias = Sequence[tuple[float, float]] class Vec2D(tuple[float, float]): - def __new__(cls: type[Self], x: float, y: float) -> Self: ... + def __new__(cls, x: float, y: float) -> Self: ... def __add__(self, other: tuple[float, float]) -> Vec2D: ... # type: ignore[override] @overload # type: ignore[override] def __mul__(self, other: Vec2D) -> float: ... @@ -366,7 +365,7 @@ class RawTurtle(TPen, TNavigator): def setundobuffer(self, size: int | None) -> None: ... def undobufferentries(self) -> int: ... def clear(self) -> None: ... - def clone(self: Self) -> Self: ... + def clone(self) -> Self: ... @overload def shape(self, name: None = None) -> str: ... @overload @@ -411,7 +410,7 @@ class RawTurtle(TPen, TNavigator): def end_poly(self) -> None: ... def get_poly(self) -> _PolygonCoords | None: ... def getscreen(self) -> TurtleScreen: ... - def getturtle(self: Self) -> Self: ... + def getturtle(self) -> Self: ... getpen = getturtle def onclick(self, fun: Callable[[float, float], object], btn: int = 1, add: bool | None = None) -> None: ... def onrelease(self, fun: Callable[[float, float], object], btn: int = 1, add: bool | None = None) -> None: ... diff --git a/mypy/typeshed/stdlib/types.pyi b/mypy/typeshed/stdlib/types.pyi index 5fb24106685e..d529b3d9ad1a 100644 --- a/mypy/typeshed/stdlib/types.pyi +++ b/mypy/typeshed/stdlib/types.pyi @@ -363,7 +363,7 @@ class GeneratorType(Generator[_T_co, _T_contra, _V_co]): self, __typ: type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ... ) -> _T_co: ... @overload - def throw(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> _T_co: ... + def throw(self, __typ: BaseException, __val: None = None, __tb: TracebackType | None = ...) -> _T_co: ... @final class AsyncGeneratorType(AsyncGenerator[_T_co, _T_contra]): @@ -379,7 +379,7 @@ class AsyncGeneratorType(AsyncGenerator[_T_co, _T_contra]): self, __typ: type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ... ) -> _T_co: ... @overload - async def athrow(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> _T_co: ... + async def athrow(self, __typ: BaseException, __val: None = None, __tb: TracebackType | None = ...) -> _T_co: ... def aclose(self) -> Coroutine[Any, Any, None]: ... if sys.version_info >= (3, 9): def __class_getitem__(cls, __item: Any) -> GenericAlias: ... @@ -402,7 +402,7 @@ class CoroutineType(Coroutine[_T_co, _T_contra, _V_co]): self, __typ: type[BaseException], __val: BaseException | object = ..., __tb: TracebackType | None = ... ) -> _T_co: ... @overload - def throw(self, __typ: BaseException, __val: None = ..., __tb: TracebackType | None = ...) -> _T_co: ... + def throw(self, __typ: BaseException, __val: None = None, __tb: TracebackType | None = ...) -> _T_co: ... class _StaticFunctionType: # Fictional type to correct the type of MethodType.__func__. diff --git a/mypy/typeshed/stdlib/typing.pyi b/mypy/typeshed/stdlib/typing.pyi index eaa566582fb4..d06b081d3ddc 100644 --- a/mypy/typeshed/stdlib/typing.pyi +++ b/mypy/typeshed/stdlib/typing.pyi @@ -1,6 +1,6 @@ -import _typeshed import collections # Needed by aliases like DefaultDict, see mypy issue 2986 import sys +import typing_extensions from _collections_abc import dict_items, dict_keys, dict_values from _typeshed import IdentityFunction, Incomplete, SupportsKeysAndGetItem from abc import ABCMeta, abstractmethod @@ -501,7 +501,7 @@ class MutableSequence(Sequence[_T], Generic[_T]): def reverse(self) -> None: ... def pop(self, index: int = -1) -> _T: ... def remove(self, value: _T) -> None: ... - def __iadd__(self: _typeshed.Self, values: Iterable[_T]) -> _typeshed.Self: ... + def __iadd__(self, values: Iterable[_T]) -> typing_extensions.Self: ... class AbstractSet(Collection[_T_co], Generic[_T_co]): @abstractmethod @@ -527,10 +527,10 @@ class MutableSet(AbstractSet[_T], Generic[_T]): def clear(self) -> None: ... def pop(self) -> _T: ... def remove(self, value: _T) -> None: ... - def __ior__(self: _typeshed.Self, it: AbstractSet[_T]) -> _typeshed.Self: ... # type: ignore[override,misc] - def __iand__(self: _typeshed.Self, it: AbstractSet[Any]) -> _typeshed.Self: ... - def __ixor__(self: _typeshed.Self, it: AbstractSet[_T]) -> _typeshed.Self: ... # type: ignore[override,misc] - def __isub__(self: _typeshed.Self, it: AbstractSet[Any]) -> _typeshed.Self: ... + def __ior__(self, it: AbstractSet[_T]) -> typing_extensions.Self: ... # type: ignore[override,misc] + def __iand__(self, it: AbstractSet[Any]) -> typing_extensions.Self: ... + def __ixor__(self, it: AbstractSet[_T]) -> typing_extensions.Self: ... # type: ignore[override,misc] + def __isub__(self, it: AbstractSet[Any]) -> typing_extensions.Self: ... class MappingView(Sized): def __init__(self, mapping: Mapping[Any, Any]) -> None: ... # undocumented @@ -719,7 +719,7 @@ class ByteString(Sequence[int], metaclass=ABCMeta): ... # Functions -_get_type_hints_obj_allowed_types = ( # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed +_get_type_hints_obj_allowed_types: typing_extensions.TypeAlias = ( # noqa: Y042 object | Callable[..., Any] | FunctionType @@ -783,7 +783,7 @@ class NamedTuple(tuple[Any, ...]): @overload def __init__(self, typename: str, fields: Iterable[tuple[str, Any]] = ...) -> None: ... @overload - def __init__(self, typename: str, fields: None = ..., **kwargs: Any) -> None: ... + def __init__(self, typename: str, fields: None = None, **kwargs: Any) -> None: ... @classmethod def _make(cls: Type[_T], iterable: Iterable[Any]) -> _T: ... if sys.version_info >= (3, 8): @@ -791,7 +791,7 @@ class NamedTuple(tuple[Any, ...]): else: def _asdict(self) -> collections.OrderedDict[str, Any]: ... - def _replace(self: _typeshed.Self, **kwargs: Any) -> _typeshed.Self: ... + def _replace(self, **kwargs: Any) -> typing_extensions.Self: ... # Internal mypy fallback type for all typed dicts (does not exist at runtime) # N.B. Keep this mostly in sync with typing_extensions._TypedDict/mypy_extensions._TypedDict @@ -801,7 +801,7 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta): if sys.version_info >= (3, 9): __required_keys__: ClassVar[frozenset[str]] __optional_keys__: ClassVar[frozenset[str]] - def copy(self: _typeshed.Self) -> _typeshed.Self: ... + def copy(self) -> typing_extensions.Self: ... # Using Never so that only calls using mypy plugin hook that specialize the signature # can go through. def setdefault(self, k: _Never, default: object) -> object: ... @@ -813,8 +813,8 @@ class _TypedDict(Mapping[str, object], metaclass=ABCMeta): def keys(self) -> dict_keys[str, object]: ... def values(self) -> dict_values[str, object]: ... if sys.version_info >= (3, 9): - def __or__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ... - def __ior__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ... + def __or__(self, __value: typing_extensions.Self) -> typing_extensions.Self: ... + def __ior__(self, __value: typing_extensions.Self) -> typing_extensions.Self: ... @_final class ForwardRef: diff --git a/mypy/typeshed/stdlib/typing_extensions.pyi b/mypy/typeshed/stdlib/typing_extensions.pyi index 73a41f16600d..bf3892d5709e 100644 --- a/mypy/typeshed/stdlib/typing_extensions.pyi +++ b/mypy/typeshed/stdlib/typing_extensions.pyi @@ -1,4 +1,3 @@ -import _typeshed import abc import collections import sys @@ -129,7 +128,7 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta): __required_keys__: ClassVar[frozenset[str]] __optional_keys__: ClassVar[frozenset[str]] __total__: ClassVar[bool] - def copy(self: _typeshed.Self) -> _typeshed.Self: ... + def copy(self) -> Self: ... # Using Never so that only calls using mypy plugin hook that specialize the signature # can go through. def setdefault(self, k: Never, default: object) -> object: ... @@ -141,8 +140,8 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta): def values(self) -> dict_values[str, object]: ... def __delitem__(self, k: Never) -> None: ... if sys.version_info >= (3, 9): - def __or__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ... - def __ior__(self: _typeshed.Self, __value: _typeshed.Self) -> _typeshed.Self: ... + def __or__(self, __value: Self) -> Self: ... + def __ior__(self, __value: Self) -> Self: ... # TypedDict is a (non-subscriptable) special form. TypedDict: object @@ -242,15 +241,15 @@ else: @overload def __init__(self, typename: str, fields: Iterable[tuple[str, Any]] = ...) -> None: ... @overload - def __init__(self, typename: str, fields: None = ..., **kwargs: Any) -> None: ... + def __init__(self, typename: str, fields: None = None, **kwargs: Any) -> None: ... @classmethod - def _make(cls: type[_typeshed.Self], iterable: Iterable[Any]) -> _typeshed.Self: ... + def _make(cls, iterable: Iterable[Any]) -> Self: ... if sys.version_info >= (3, 8): def _asdict(self) -> dict[str, Any]: ... else: def _asdict(self) -> collections.OrderedDict[str, Any]: ... - def _replace(self: _typeshed.Self, **kwargs: Any) -> _typeshed.Self: ... + def _replace(self, **kwargs: Any) -> Self: ... # New things in 3.xx # The `default` parameter was added to TypeVar, ParamSpec, and TypeVarTuple (PEP 696) diff --git a/mypy/typeshed/stdlib/unicodedata.pyi b/mypy/typeshed/stdlib/unicodedata.pyi index 4569d6584fd6..5a1f7fe6638d 100644 --- a/mypy/typeshed/stdlib/unicodedata.pyi +++ b/mypy/typeshed/stdlib/unicodedata.pyi @@ -1,6 +1,6 @@ import sys from _typeshed import ReadOnlyBuffer -from typing import Any, TypeVar +from typing import Any, TypeVar, overload from typing_extensions import Literal, TypeAlias, final ucd_3_2_0: UCD @@ -14,9 +14,15 @@ _T = TypeVar("_T") def bidirectional(__chr: str) -> str: ... def category(__chr: str) -> str: ... def combining(__chr: str) -> int: ... -def decimal(__chr: str, __default: _T = ...) -> int | _T: ... +@overload +def decimal(__chr: str) -> int: ... +@overload +def decimal(__chr: str, __default: _T) -> int | _T: ... def decomposition(__chr: str) -> str: ... -def digit(__chr: str, __default: _T = ...) -> int | _T: ... +@overload +def digit(__chr: str) -> int: ... +@overload +def digit(__chr: str, __default: _T) -> int | _T: ... _EastAsianWidth: TypeAlias = Literal["F", "H", "W", "Na", "A", "N"] @@ -27,26 +33,44 @@ if sys.version_info >= (3, 8): def lookup(__name: str | ReadOnlyBuffer) -> str: ... def mirrored(__chr: str) -> int: ... -def name(__chr: str, __default: _T = ...) -> str | _T: ... +@overload +def name(__chr: str) -> str: ... +@overload +def name(__chr: str, __default: _T) -> str | _T: ... def normalize(__form: str, __unistr: str) -> str: ... -def numeric(__chr: str, __default: _T = ...) -> float | _T: ... +@overload +def numeric(__chr: str) -> float: ... +@overload +def numeric(__chr: str, __default: _T) -> float | _T: ... @final class UCD: # The methods below are constructed from the same array in C - # (unicodedata_functions) and hence identical to the methods above. + # (unicodedata_functions) and hence identical to the functions above. unidata_version: str def bidirectional(self, __chr: str) -> str: ... def category(self, __chr: str) -> str: ... def combining(self, __chr: str) -> int: ... - def decimal(self, __chr: str, __default: _T = ...) -> int | _T: ... + @overload + def decimal(self, __chr: str) -> int: ... + @overload + def decimal(self, __chr: str, __default: _T) -> int | _T: ... def decomposition(self, __chr: str) -> str: ... - def digit(self, __chr: str, __default: _T = ...) -> int | _T: ... + @overload + def digit(self, __chr: str) -> int: ... + @overload + def digit(self, __chr: str, __default: _T) -> int | _T: ... def east_asian_width(self, __chr: str) -> _EastAsianWidth: ... if sys.version_info >= (3, 8): def is_normalized(self, __form: str, __unistr: str) -> bool: ... def lookup(self, __name: str | ReadOnlyBuffer) -> str: ... def mirrored(self, __chr: str) -> int: ... - def name(self, __chr: str, __default: _T = ...) -> str | _T: ... + @overload + def name(self, __chr: str) -> str: ... + @overload + def name(self, __chr: str, __default: _T) -> str | _T: ... def normalize(self, __form: str, __unistr: str) -> str: ... - def numeric(self, __chr: str, __default: _T = ...) -> float | _T: ... + @overload + def numeric(self, __chr: str) -> float: ... + @overload + def numeric(self, __chr: str, __default: _T) -> float | _T: ... diff --git a/mypy/typeshed/stdlib/unittest/case.pyi b/mypy/typeshed/stdlib/unittest/case.pyi index 5b1bd9288659..8f8cf43385a8 100644 --- a/mypy/typeshed/stdlib/unittest/case.pyi +++ b/mypy/typeshed/stdlib/unittest/case.pyi @@ -1,26 +1,13 @@ import logging import sys import unittest.result -from _typeshed import Self, SupportsDunderGE, SupportsDunderGT, SupportsDunderLE, SupportsDunderLT, SupportsRSub, SupportsSub +from _typeshed import SupportsDunderGE, SupportsDunderGT, SupportsDunderLE, SupportsDunderLT, SupportsRSub, SupportsSub from collections.abc import Callable, Container, Iterable, Mapping, Sequence, Set as AbstractSet from contextlib import AbstractContextManager from re import Pattern from types import TracebackType -from typing import ( - Any, - AnyStr, - ClassVar, - Generic, - NamedTuple, - NoReturn, - Protocol, - SupportsAbs, - SupportsRound, - TypeVar, - Union, - overload, -) -from typing_extensions import ParamSpec, TypeAlias +from typing import Any, AnyStr, ClassVar, Generic, NamedTuple, NoReturn, Protocol, SupportsAbs, SupportsRound, TypeVar, overload +from typing_extensions import ParamSpec, Self, TypeAlias from warnings import WarningMessage if sys.version_info >= (3, 9): @@ -82,9 +69,9 @@ class SkipTest(Exception): class _SupportsAbsAndDunderGE(SupportsDunderGE[Any], SupportsAbs[Any], Protocol): ... if sys.version_info >= (3, 10): - _IsInstanceClassInfo: TypeAlias = Union[type, UnionType, tuple[type | UnionType | tuple[Any, ...], ...]] + _IsInstanceClassInfo: TypeAlias = type | UnionType | tuple[type | UnionType | tuple[Any, ...], ...] else: - _IsInstanceClassInfo: TypeAlias = Union[type, tuple[type | tuple[Any, ...], ...]] + _IsInstanceClassInfo: TypeAlias = type | tuple[type | tuple[Any, ...], ...] class TestCase: failureException: type[BaseException] @@ -317,7 +304,7 @@ class FunctionTestCase(TestCase): class _AssertRaisesContext(Generic[_E]): exception: _E - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, tb: TracebackType | None ) -> bool: ... @@ -329,7 +316,7 @@ class _AssertWarnsContext: filename: str lineno: int warnings: list[WarningMessage] - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, tb: TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/unittest/mock.pyi b/mypy/typeshed/stdlib/unittest/mock.pyi index 54c79fd433d2..f0345c903a3b 100644 --- a/mypy/typeshed/stdlib/unittest/mock.pyi +++ b/mypy/typeshed/stdlib/unittest/mock.pyi @@ -1,10 +1,9 @@ import sys -from _typeshed import Self from collections.abc import Awaitable, Callable, Coroutine, Iterable, Mapping, Sequence from contextlib import _GeneratorContextManager from types import TracebackType from typing import Any, Generic, TypeVar, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Final, Literal, Self, TypeAlias _T = TypeVar("_T") _TT = TypeVar("_TT", bound=type[Any]) @@ -48,7 +47,7 @@ else: "seal", ) -__version__: str +__version__: Final[str] FILTER_DIR: Any @@ -68,12 +67,7 @@ _CallValue: TypeAlias = str | tuple[Any, ...] | Mapping[str, Any] | _ArgsKwargs class _Call(tuple[Any, ...]): def __new__( - cls: type[Self], - value: _CallValue = ..., - name: str | None = "", - parent: Any | None = None, - two: bool = False, - from_kall: bool = True, + cls, value: _CallValue = ..., name: str | None = "", parent: Any | None = None, two: bool = False, from_kall: bool = True ) -> Self: ... name: Any parent: Any @@ -107,8 +101,10 @@ class _CallList(list[_Call]): class Base: def __init__(self, *args: Any, **kwargs: Any) -> None: ... +# We subclass with "Any" because mocks are explicitly designed to stand in for other types, +# something that can't be expressed with our static type system. class NonCallableMock(Base, Any): - def __new__(__cls: type[Self], *args: Any, **kw: Any) -> Self: ... + def __new__(__cls, *args: Any, **kw: Any) -> Self: ... def __init__( self, spec: list[str] | object | type[object] | None = None, @@ -437,9 +433,9 @@ def mock_open(mock: Any | None = None, read_data: Any = "") -> Any: ... class PropertyMock(Mock): if sys.version_info >= (3, 8): - def __get__(self: Self, obj: _T, obj_type: type[_T] | None = None) -> Self: ... + def __get__(self, obj: _T, obj_type: type[_T] | None = None) -> Self: ... else: - def __get__(self: Self, obj: _T, obj_type: type[_T] | None) -> Self: ... + def __get__(self, obj: _T, obj_type: type[_T] | None) -> Self: ... def __set__(self, obj: Any, value: Any) -> None: ... diff --git a/mypy/typeshed/stdlib/urllib/error.pyi b/mypy/typeshed/stdlib/urllib/error.pyi index 8ea25680f1a4..89cec9bf289c 100644 --- a/mypy/typeshed/stdlib/urllib/error.pyi +++ b/mypy/typeshed/stdlib/urllib/error.pyi @@ -4,13 +4,15 @@ from urllib.response import addinfourl __all__ = ["URLError", "HTTPError", "ContentTooShortError"] -class URLError(IOError): +class URLError(OSError): reason: str | BaseException def __init__(self, reason: str | BaseException, filename: str | None = None) -> None: ... class HTTPError(URLError, addinfourl): @property - def headers(self) -> Message: ... # type: ignore[override] + def headers(self) -> Message: ... + @headers.setter + def headers(self, headers: Message) -> None: ... @property def reason(self) -> str: ... # type: ignore[override] code: int diff --git a/mypy/typeshed/stdlib/urllib/response.pyi b/mypy/typeshed/stdlib/urllib/response.pyi index 4db1b5649c7a..61ba687076b2 100644 --- a/mypy/typeshed/stdlib/urllib/response.pyi +++ b/mypy/typeshed/stdlib/urllib/response.pyi @@ -1,20 +1,21 @@ import sys -from _typeshed import ReadableBuffer, Self +from _typeshed import ReadableBuffer from collections.abc import Callable, Iterable from email.message import Message from types import TracebackType from typing import IO, Any, BinaryIO +from typing_extensions import Self __all__ = ["addbase", "addclosehook", "addinfo", "addinfourl"] class addbase(BinaryIO): fp: IO[bytes] def __init__(self, fp: IO[bytes]) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... - def __iter__(self: Self) -> Self: ... + def __iter__(self) -> Self: ... def __next__(self) -> bytes: ... def close(self) -> None: ... # These methods don't actually exist, but the class inherits at runtime from diff --git a/mypy/typeshed/stdlib/uu.pyi b/mypy/typeshed/stdlib/uu.pyi index 20e79bf3fec9..324053e04337 100644 --- a/mypy/typeshed/stdlib/uu.pyi +++ b/mypy/typeshed/stdlib/uu.pyi @@ -10,4 +10,4 @@ class Error(Exception): ... def encode( in_file: _File, out_file: _File, name: str | None = None, mode: int | None = None, *, backtick: bool = False ) -> None: ... -def decode(in_file: _File, out_file: _File | None = None, mode: int | None = None, quiet: int = False) -> None: ... +def decode(in_file: _File, out_file: _File | None = None, mode: int | None = None, quiet: bool = False) -> None: ... diff --git a/mypy/typeshed/stdlib/wave.pyi b/mypy/typeshed/stdlib/wave.pyi index 3817ae09307f..0d004d6b2d8a 100644 --- a/mypy/typeshed/stdlib/wave.pyi +++ b/mypy/typeshed/stdlib/wave.pyi @@ -1,7 +1,7 @@ import sys -from _typeshed import ReadableBuffer, Self, Unused +from _typeshed import ReadableBuffer, Unused from typing import IO, Any, BinaryIO, NamedTuple, NoReturn, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias if sys.version_info >= (3, 9): __all__ = ["open", "Error", "Wave_read", "Wave_write"] @@ -24,7 +24,7 @@ class _wave_params(NamedTuple): class Wave_read: def __init__(self, f: _File) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... def getfp(self) -> BinaryIO | None: ... def rewind(self) -> None: ... @@ -44,7 +44,7 @@ class Wave_read: class Wave_write: def __init__(self, f: _File) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, *args: Unused) -> None: ... def setnchannels(self, nchannels: int) -> None: ... def getnchannels(self) -> int: ... diff --git a/mypy/typeshed/stdlib/weakref.pyi b/mypy/typeshed/stdlib/weakref.pyi index a0f35b4f51eb..1e0aac814dfb 100644 --- a/mypy/typeshed/stdlib/weakref.pyi +++ b/mypy/typeshed/stdlib/weakref.pyi @@ -1,5 +1,5 @@ import sys -from _typeshed import Self, SupportsKeysAndGetItem +from _typeshed import SupportsKeysAndGetItem from _weakref import ( CallableProxyType as CallableProxyType, ProxyType as ProxyType, @@ -12,7 +12,7 @@ from _weakref import ( from _weakrefset import WeakSet as WeakSet from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping from typing import Any, Generic, TypeVar, overload -from typing_extensions import ParamSpec +from typing_extensions import ParamSpec, Self __all__ = [ "ref", @@ -41,7 +41,7 @@ _P = ParamSpec("_P") ProxyTypes: tuple[type[Any], ...] class WeakMethod(ref[_CallableT], Generic[_CallableT]): - def __new__(cls: type[Self], meth: _CallableT, callback: Callable[[_CallableT], object] | None = None) -> Self: ... + def __new__(cls, meth: _CallableT, callback: Callable[[_CallableT], object] | None = None) -> Self: ... def __call__(self) -> _CallableT | None: ... def __eq__(self, other: object) -> bool: ... def __ne__(self, other: object) -> bool: ... @@ -63,7 +63,7 @@ class WeakValueDictionary(MutableMapping[_KT, _VT]): def __iter__(self) -> Iterator[_KT]: ... def copy(self) -> WeakValueDictionary[_KT, _VT]: ... __copy__ = copy - def __deepcopy__(self: Self, memo: Any) -> Self: ... + def __deepcopy__(self, memo: Any) -> Self: ... # These are incompatible with Mapping def keys(self) -> Iterator[_KT]: ... # type: ignore[override] def values(self) -> Iterator[_VT]: ... # type: ignore[override] @@ -80,14 +80,14 @@ class WeakValueDictionary(MutableMapping[_KT, _VT]): def __ror__(self, other: Mapping[_T1, _T2]) -> WeakValueDictionary[_KT | _T1, _VT | _T2]: ... # WeakValueDictionary.__ior__ should be kept roughly in line with MutableMapping.update() @overload # type: ignore[misc] - def __ior__(self: Self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... + def __ior__(self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... @overload - def __ior__(self: Self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... + def __ior__(self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... class KeyedRef(ref[_T], Generic[_KT, _T]): key: _KT # This __new__ method uses a non-standard name for the "cls" parameter - def __new__(type: type[Self], ob: _T, callback: Callable[[_T], Any], key: _KT) -> Self: ... + def __new__(type, ob: _T, callback: Callable[[_T], Any], key: _KT) -> Self: ... def __init__(self, ob: _T, callback: Callable[[_T], Any], key: _KT) -> None: ... class WeakKeyDictionary(MutableMapping[_KT, _VT]): @@ -103,7 +103,7 @@ class WeakKeyDictionary(MutableMapping[_KT, _VT]): def __iter__(self) -> Iterator[_KT]: ... def copy(self) -> WeakKeyDictionary[_KT, _VT]: ... __copy__ = copy - def __deepcopy__(self: Self, memo: Any) -> Self: ... + def __deepcopy__(self, memo: Any) -> Self: ... # These are incompatible with Mapping def keys(self) -> Iterator[_KT]: ... # type: ignore[override] def values(self) -> Iterator[_VT]: ... # type: ignore[override] @@ -123,9 +123,9 @@ class WeakKeyDictionary(MutableMapping[_KT, _VT]): def __ror__(self, other: Mapping[_T1, _T2]) -> WeakKeyDictionary[_KT | _T1, _VT | _T2]: ... # WeakKeyDictionary.__ior__ should be kept roughly in line with MutableMapping.update() @overload # type: ignore[misc] - def __ior__(self: Self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... + def __ior__(self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... @overload - def __ior__(self: Self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... + 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: ... diff --git a/mypy/typeshed/stdlib/webbrowser.pyi b/mypy/typeshed/stdlib/webbrowser.pyi index d15ae49fd1e8..02edd42e7d59 100644 --- a/mypy/typeshed/stdlib/webbrowser.pyi +++ b/mypy/typeshed/stdlib/webbrowser.pyi @@ -65,4 +65,9 @@ if sys.platform == "darwin": def open(self, url: str, new: int = 0, autoraise: bool = True) -> bool: ... class MacOSXOSAScript(BaseBrowser): # In runtime this class does not have `name` and `basename` + if sys.version_info >= (3, 11): + def __init__(self, name: str = "default") -> None: ... + else: + def __init__(self, name: str) -> None: ... + def open(self, url: str, new: int = 0, autoraise: bool = True) -> bool: ... diff --git a/mypy/typeshed/stdlib/winreg.pyi b/mypy/typeshed/stdlib/winreg.pyi index 6377492babc7..5b2d09a3bebc 100644 --- a/mypy/typeshed/stdlib/winreg.pyi +++ b/mypy/typeshed/stdlib/winreg.pyi @@ -1,8 +1,7 @@ import sys -from _typeshed import Self from types import TracebackType from typing import Any -from typing_extensions import Literal, TypeAlias, final +from typing_extensions import Literal, Self, TypeAlias, final if sys.platform == "win32": _KeyType: TypeAlias = HKEYType | int @@ -93,7 +92,7 @@ if sys.platform == "win32": class HKEYType: def __bool__(self) -> bool: ... def __int__(self) -> int: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None ) -> bool | None: ... diff --git a/mypy/typeshed/stdlib/xml/dom/minidom.pyi b/mypy/typeshed/stdlib/xml/dom/minidom.pyi index d996f66984f9..7bbffb88c8f7 100644 --- a/mypy/typeshed/stdlib/xml/dom/minidom.pyi +++ b/mypy/typeshed/stdlib/xml/dom/minidom.pyi @@ -1,7 +1,7 @@ import sys import xml.dom -from _typeshed import Incomplete, ReadableBuffer, Self, SupportsRead, SupportsWrite -from typing_extensions import Literal +from _typeshed import Incomplete, ReadableBuffer, SupportsRead, SupportsWrite +from typing_extensions import Literal, Self from xml.dom.xmlbuilder import DocumentLS, DOMImplementationLS from xml.sax.xmlreader import XMLReader @@ -46,7 +46,7 @@ class Node(xml.dom.Node): def setUserData(self, key, data, handler): ... childNodes: Incomplete def unlink(self) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__(self, et, ev, tb) -> None: ... class DocumentFragment(Node): @@ -269,7 +269,7 @@ class DOMImplementation(DOMImplementationLS): def hasFeature(self, feature: str, version: str | None) -> bool: ... def createDocument(self, namespaceURI: str | None, qualifiedName: str | None, doctype: DocumentType | None) -> Document: ... def createDocumentType(self, qualifiedName: str | None, publicId: str, systemId: str) -> DocumentType: ... - def getInterface(self: Self, feature: str) -> Self | None: ... + def getInterface(self, feature: str) -> Self | None: ... class ElementInfo: tagName: Incomplete diff --git a/mypy/typeshed/stdlib/xml/sax/__init__.pyi b/mypy/typeshed/stdlib/xml/sax/__init__.pyi index a591258db801..ca981a00d25f 100644 --- a/mypy/typeshed/stdlib/xml/sax/__init__.pyi +++ b/mypy/typeshed/stdlib/xml/sax/__init__.pyi @@ -1,5 +1,5 @@ import sys -from _typeshed import ReadableBuffer, SupportsRead, _T_co +from _typeshed import ReadableBuffer, StrPath, SupportsRead, _T_co from collections.abc import Iterable from typing import Any, NoReturn, Protocol from xml.sax.handler import ContentHandler as ContentHandler, ErrorHandler as ErrorHandler @@ -29,12 +29,19 @@ default_parser_list: list[str] if sys.version_info >= (3, 8): def make_parser(parser_list: Iterable[str] = ...) -> XMLReader: ... + def parse( + source: StrPath | _SupportsReadClose[bytes] | _SupportsReadClose[str], + handler: ContentHandler, + errorHandler: ErrorHandler = ..., + ) -> None: ... else: def make_parser(parser_list: list[str] = ...) -> XMLReader: ... + def parse( + source: str | _SupportsReadClose[bytes] | _SupportsReadClose[str], + handler: ContentHandler, + errorHandler: ErrorHandler = ..., + ) -> None: ... -def parse( - source: str | _SupportsReadClose[bytes] | _SupportsReadClose[str], handler: ContentHandler, errorHandler: ErrorHandler = ... -) -> None: ... def parseString(string: ReadableBuffer | str, handler: ContentHandler, errorHandler: ErrorHandler | None = ...) -> None: ... def _create_parser(parser_name: str) -> XMLReader: ... diff --git a/mypy/typeshed/stdlib/xmlrpc/client.pyi b/mypy/typeshed/stdlib/xmlrpc/client.pyi index 536cd6382d0b..7bf701ae716d 100644 --- a/mypy/typeshed/stdlib/xmlrpc/client.pyi +++ b/mypy/typeshed/stdlib/xmlrpc/client.pyi @@ -2,13 +2,13 @@ import gzip import http.client import sys import time -from _typeshed import ReadableBuffer, Self, SupportsRead, SupportsWrite, _BufferWithLen +from _typeshed import ReadableBuffer, SupportsRead, SupportsWrite, _BufferWithLen from collections.abc import Callable, Iterable, Mapping from datetime import datetime from io import BytesIO from types import TracebackType -from typing import Any, Protocol, Union, overload -from typing_extensions import Literal, TypeAlias +from typing import Any, Protocol, overload +from typing_extensions import Literal, Self, TypeAlias class _SupportsTimeTuple(Protocol): def timetuple(self) -> time.struct_time: ... @@ -31,7 +31,7 @@ _Marshallable: TypeAlias = ( | Binary ) _XMLDate: TypeAlias = int | datetime | tuple[int, ...] | time.struct_time -_HostType: TypeAlias = Union[tuple[str, dict[str, str]], str] +_HostType: TypeAlias = tuple[str, dict[str, str]] | str def escape(s: str) -> str: ... # undocumented @@ -312,7 +312,7 @@ class ServerProxy: def __call__(self, attr: Literal["transport"]) -> Transport: ... @overload def __call__(self, attr: str) -> Callable[[], None] | Transport: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/mypy/typeshed/stdlib/zipfile.pyi b/mypy/typeshed/stdlib/zipfile.pyi index 0cb6138dfddd..b969d0cf9e6a 100644 --- a/mypy/typeshed/stdlib/zipfile.pyi +++ b/mypy/typeshed/stdlib/zipfile.pyi @@ -1,11 +1,11 @@ import io import sys -from _typeshed import Self, StrOrBytesPath, StrPath, _BufferWithLen +from _typeshed import StrOrBytesPath, StrPath, _BufferWithLen from collections.abc import Callable, Iterable, Iterator from os import PathLike from types import TracebackType from typing import IO, Any, Protocol, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, Self, TypeAlias __all__ = [ "BadZipFile", @@ -150,7 +150,7 @@ class ZipFile: compresslevel: int | None = None, ) -> None: ... - def __enter__(self: Self) -> Self: ... + def __enter__(self) -> Self: ... def __exit__( self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> None: ... @@ -214,12 +214,10 @@ class ZipInfo: def __init__(self, filename: str = "NoName", date_time: _DateTuple = ...) -> None: ... if sys.version_info >= (3, 8): @classmethod - def from_file( - cls: type[Self], filename: StrPath, arcname: StrPath | None = None, *, strict_timestamps: bool = True - ) -> Self: ... + def from_file(cls, filename: StrPath, arcname: StrPath | None = None, *, strict_timestamps: bool = True) -> Self: ... else: @classmethod - def from_file(cls: type[Self], filename: StrPath, arcname: StrPath | None = None) -> Self: ... + def from_file(cls, filename: StrPath, arcname: StrPath | None = None) -> Self: ... def is_dir(self) -> bool: ... def FileHeader(self, zip64: bool | None = None) -> bytes: ... diff --git a/mypy/typeshed/stdlib/zoneinfo/__init__.pyi b/mypy/typeshed/stdlib/zoneinfo/__init__.pyi index 0bdf853f4069..fe994be3e8ff 100644 --- a/mypy/typeshed/stdlib/zoneinfo/__init__.pyi +++ b/mypy/typeshed/stdlib/zoneinfo/__init__.pyi @@ -1,7 +1,8 @@ -from _typeshed import Self, StrPath +from _typeshed import StrPath from collections.abc import Iterable, Sequence from datetime import datetime, timedelta, tzinfo from typing import Any, Protocol +from typing_extensions import Self __all__ = ["ZoneInfo", "reset_tzpath", "available_timezones", "TZPATH", "ZoneInfoNotFoundError", "InvalidTZPathWarning"] @@ -14,9 +15,9 @@ class ZoneInfo(tzinfo): def key(self) -> str: ... def __init__(self, key: str) -> None: ... @classmethod - def no_cache(cls: type[Self], key: str) -> Self: ... + def no_cache(cls, key: str) -> Self: ... @classmethod - def from_file(cls: type[Self], __fobj: _IOBytes, key: str | None = ...) -> Self: ... + def from_file(cls, __fobj: _IOBytes, key: str | None = ...) -> Self: ... @classmethod def clear_cache(cls, *, only_keys: Iterable[str] | None = ...) -> None: ... def tzname(self, __dt: datetime | None) -> str | None: ...