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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions stdlib/_asyncio.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from collections.abc import Awaitable, Callable, Coroutine, Generator
from contextvars import Context
from types import FrameType, GenericAlias
from typing import Any, Literal, TextIO, TypeAlias, TypeVar
from typing_extensions import Self, disjoint_base
from typing_extensions import Self, TypeForm, disjoint_base

_T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
Expand Down Expand Up @@ -39,7 +39,7 @@ class Future(Awaitable[_T]):
def __await__(self) -> Generator[Any, None, _T]: ...
@property
def _loop(self) -> AbstractEventLoop: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

if sys.version_info >= (3, 12):
_TaskCompatibleCoro: TypeAlias = Coroutine[Any, Any, _T_co]
Expand Down Expand Up @@ -92,7 +92,7 @@ class Task(Future[_T_co]): # type: ignore[type-var] # pyright: ignore[reportIn
def cancelling(self) -> int: ...
def uncancel(self) -> int: ...

def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

def get_event_loop() -> AbstractEventLoop: ...
def get_running_loop() -> AbstractEventLoop: ...
Expand Down
6 changes: 3 additions & 3 deletions stdlib/_contextvars.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sys
from collections.abc import Callable, Iterator, Mapping
from types import GenericAlias, TracebackType
from typing import Any, ClassVar, Generic, ParamSpec, TypeVar, final, overload
from typing_extensions import Self
from typing_extensions import Self, TypeForm

_T = TypeVar("_T")
_D = TypeVar("_D")
Expand All @@ -25,7 +25,7 @@ class ContextVar(Generic[_T]):
def get(self, default: _D, /) -> _D | _T: ...
def set(self, value: _T, /) -> Token[_T]: ...
def reset(self, token: Token[_T], /) -> None: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

@final
class Token(Generic[_T]):
Expand All @@ -35,7 +35,7 @@ class Token(Generic[_T]):
def old_value(self) -> Any: ... # returns either _T or MISSING, but that's hard to express
MISSING: ClassVar[object]
__hash__: ClassVar[None] # type: ignore[assignment]
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...
if sys.version_info >= (3, 14):
def __enter__(self) -> Self: ...
def __exit__(
Expand Down
4 changes: 2 additions & 2 deletions stdlib/_ctypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
from ctypes import CDLL, ArgumentError as ArgumentError, c_void_p
from types import GenericAlias
from typing import Any, ClassVar, Final, Generic, Literal, SupportsIndex, TypeAlias, TypeVar, final, overload, type_check_only
from typing_extensions import Self
from typing_extensions import Self, TypeForm

_T = TypeVar("_T")
_CT = TypeVar("_CT", bound=_CData)
Expand Down Expand Up @@ -344,7 +344,7 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType):
# Can't inherit from Sized because the metaclass conflict between
# Sized and _CData prevents using _CDataMeta.
def __len__(self) -> int: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

def addressof(obj: _CData | _CDataType, /) -> int: ...
def alignment(obj_or_type: _CData | _CDataType | type[_CData | _CDataType], /) -> int: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/_queue.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from types import GenericAlias
from typing import Any, Generic, TypeVar
from typing_extensions import disjoint_base
from typing_extensions import TypeForm, disjoint_base

_T = TypeVar("_T")

Expand All @@ -15,4 +15,4 @@ class SimpleQueue(Generic[_T]):
def put(self, item: _T, block: bool = True, timeout: float | None = None) -> None: ...
def put_nowait(self, item: _T) -> None: ...
def qsize(self) -> int: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...
4 changes: 2 additions & 2 deletions stdlib/_weakrefset.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections.abc import Iterable, Iterator, MutableSet
from types import GenericAlias
from typing import Any, ClassVar, TypeVar, overload
from typing_extensions import Self
from typing_extensions import Self, TypeForm

__all__ = ["WeakSet"]

Expand Down Expand Up @@ -45,4 +45,4 @@ class WeakSet(MutableSet[_T]):
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: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...
4 changes: 2 additions & 2 deletions stdlib/array.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer, SupportsRead, SupportsWrite
from collections.abc import Iterable, MutableSequence
from types import GenericAlias
from typing import Any, ClassVar, Literal, SupportsIndex, TypeAlias, TypeVar, overload
from typing_extensions import Self, deprecated, disjoint_base
from typing_extensions import Self, TypeForm, deprecated, disjoint_base

_IntTypeCode: TypeAlias = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"]
if sys.version_info >= (3, 15):
Expand Down Expand Up @@ -103,6 +103,6 @@ class array(MutableSequence[_T]):
def __buffer__(self, flags: int, /) -> memoryview: ...
def __release_buffer__(self, buffer: memoryview, /) -> None: ...
if sys.version_info >= (3, 12):
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

ArrayType = array
35 changes: 22 additions & 13 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,16 @@ from typing import ( # noqa: Y022,UP035
)

# we can't import `Literal` from typing or mypy crashes: see #11247
from typing_extensions import Literal, LiteralString, Self, TypeIs, TypeVarTuple, deprecated, disjoint_base # noqa: Y023, UP035
from typing_extensions import ( # noqa: Y023, UP035
Literal,
LiteralString,
Self,
TypeForm,
TypeIs,
TypeVarTuple,
deprecated,
disjoint_base,
)

if sys.version_info >= (3, 14):
from _typeshed import AnnotateFunc
Expand Down Expand Up @@ -150,7 +159,7 @@ class staticmethod(Generic[_P, _R_co]):
def __wrapped__(self) -> Callable[_P, _R_co]: ...
def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R_co: ...
if sys.version_info >= (3, 14):
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...
__annotate__: AnnotateFunc | None

@disjoint_base
Expand All @@ -169,7 +178,7 @@ class classmethod(Generic[_T, _P, _R_co]):
@property
def __wrapped__(self) -> Callable[Concatenate[type[_T], _P], _R_co]: ...
if sys.version_info >= (3, 14):
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...
__annotate__: AnnotateFunc | None

@disjoint_base
Expand Down Expand Up @@ -975,7 +984,7 @@ class memoryview(Sequence[_I]):
count: ClassVar[None] # type: ignore[assignment]

if sys.version_info >= (3, 14):
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

@final
class bool(int):
Expand Down Expand Up @@ -1050,7 +1059,7 @@ class slice(Generic[_StartT_co, _StopT_co, _StepT_co]):

def indices(self, len: SupportsIndex, /) -> tuple[int, int, int]: ...
if sys.version_info >= (3, 15):
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

@disjoint_base
class tuple(Sequence[_T_co]):
Expand All @@ -1076,7 +1085,7 @@ class tuple(Sequence[_T_co]):
def __rmul__(self, value: SupportsIndex, /) -> tuple[_T_co, ...]: ...
def count(self, value: Any, /) -> int: ...
def index(self, value: Any, start: SupportsIndex = 0, stop: SupportsIndex = sys.maxsize, /) -> int: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

# Doesn't exist at runtime, but deleting this breaks mypy and pyright. See:
# https://github.com/python/typeshed/issues/7580
Expand Down Expand Up @@ -1181,7 +1190,7 @@ class list(MutableSequence[_T]):
def __lt__(self, value: list[_T], /) -> bool: ...
def __le__(self, value: list[_T], /) -> bool: ...
def __eq__(self, value: object, /) -> bool: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

@disjoint_base
class dict(MutableMapping[_KT, _VT]):
Expand Down Expand Up @@ -1251,7 +1260,7 @@ class dict(MutableMapping[_KT, _VT]):
def __eq__(self, value: object, /) -> bool: ...
def __reversed__(self) -> Iterator[_KT]: ...
__hash__: ClassVar[None] # type: ignore[assignment]
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...
if sys.version_info >= (3, 15):
def __or__(self, value: dict[_T1, _T2] | frozendict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ...
@overload
Expand Down Expand Up @@ -1308,7 +1317,7 @@ if sys.version_info >= (3, 15):
def __reversed__(self) -> Iterator[_KT]: ...
def __iter__(self) -> Iterator[_KT]: ...
def __hash__(self) -> int: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...
def __or__(self, value: dict[_T1, _T2] | frozendict[_T1, _T2], /) -> frozendict[_KT | _T1, _VT | _T2]: ...
@overload
def __ror__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ...
Expand Down Expand Up @@ -1353,7 +1362,7 @@ class set(MutableSet[_T]):
def __gt__(self, value: AbstractSet[object], /) -> bool: ...
def __eq__(self, value: object, /) -> bool: ...
__hash__: ClassVar[None] # type: ignore[assignment]
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

@disjoint_base
class frozenset(AbstractSet[_T_co]):
Expand Down Expand Up @@ -1382,14 +1391,14 @@ class frozenset(AbstractSet[_T_co]):
def __gt__(self, value: AbstractSet[object], /) -> bool: ...
def __eq__(self, value: object, /) -> bool: ...
def __hash__(self) -> int: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

@disjoint_base
class enumerate(Generic[_T]):
def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> tuple[int, _T]: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

@final
class range(Sequence[int]):
Expand Down Expand Up @@ -2399,7 +2408,7 @@ if sys.version_info >= (3, 11):
def derive(self, excs: Sequence[_ExceptionT], /) -> ExceptionGroup[_ExceptionT]: ...
@overload
def derive(self, excs: Sequence[_BaseExceptionT], /) -> BaseExceptionGroup[_BaseExceptionT]: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

class ExceptionGroup(BaseExceptionGroup[_ExceptionT_co], Exception):
def __new__(cls, message: str, exceptions: Sequence[_ExceptionT_co], /) -> Self: ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/collections/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ from collections.abc import (
)
from types import GenericAlias
from typing import Any, ClassVar, Generic, NoReturn, SupportsIndex, TypeVar, final, overload, type_check_only
from typing_extensions import Self, disjoint_base
from typing_extensions import Self, TypeForm, disjoint_base

if sys.version_info >= (3, 15):
from builtins import frozendict
Expand Down Expand Up @@ -268,7 +268,7 @@ class deque(MutableSequence[_T]):
def __gt__(self, value: deque[_T], /) -> bool: ...
def __ge__(self, value: deque[_T], /) -> bool: ...
def __eq__(self, value: object, /) -> bool: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

class Counter(dict[_T, int], Generic[_T]):
@overload
Expand Down
4 changes: 2 additions & 2 deletions stdlib/concurrent/futures/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from collections.abc import Callable, Iterable, Iterator
from logging import Logger
from types import GenericAlias, TracebackType
from typing import Any, Final, Generic, NamedTuple, ParamSpec, Protocol, TypeVar, type_check_only
from typing_extensions import Self
from typing_extensions import Self, TypeForm

FIRST_COMPLETED: Final = "FIRST_COMPLETED"
FIRST_EXCEPTION: Final = "FIRST_EXCEPTION"
Expand Down Expand Up @@ -49,7 +49,7 @@ class Future(Generic[_T]):
def set_result(self, result: _T) -> None: ...
def exception(self, timeout: float | None = None) -> BaseException | None: ...
def set_exception(self, exception: BaseException | None) -> None: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

class Executor:
def submit(self, fn: Callable[_P, _T], /, *args: _P.args, **kwargs: _P.kwargs) -> Future[_T]: ...
Expand Down
6 changes: 3 additions & 3 deletions stdlib/concurrent/futures/thread.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from collections.abc import Callable, Iterable, Mapping, Set as AbstractSet
from threading import Lock, Semaphore, Thread
from types import GenericAlias
from typing import Any, Generic, Protocol, TypeAlias, TypeVar, overload, type_check_only
from typing_extensions import Self, TypeVarTuple, Unpack
from typing_extensions import Self, TypeForm, TypeVarTuple, Unpack
from weakref import ref

from ._base import BrokenExecutor, Executor, Future
Expand Down Expand Up @@ -57,7 +57,7 @@ if sys.version_info >= (3, 14):
task: _Task
def __init__(self, future: Future[Any], task: _Task) -> None: ...
def run(self, ctx: WorkerContext) -> None: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

def _worker(executor_reference: ref[Any], ctx: WorkerContext, work_queue: queue.SimpleQueue[Any]) -> None: ...

Expand All @@ -69,7 +69,7 @@ else:
kwargs: Mapping[str, Any]
def __init__(self, future: Future[_S], fn: Callable[..., _S], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ...
def run(self) -> None: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

def _worker(
executor_reference: ref[Any],
Expand Down
6 changes: 3 additions & 3 deletions stdlib/csv.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ from _typeshed import SupportsWrite
from collections.abc import Collection, Iterable, Mapping, Sequence
from types import GenericAlias
from typing import Any, Generic, Literal, TypeVar, overload
from typing_extensions import Self
from typing_extensions import Self, TypeForm

__all__ = [
"QUOTE_MINIMAL",
Expand Down Expand Up @@ -115,7 +115,7 @@ class DictReader(Generic[_T]):
def __iter__(self) -> Self: ...
def __next__(self) -> dict[_T | Any, str | Any]: ...
if sys.version_info >= (3, 12):
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

class DictWriter(Generic[_T]):
fieldnames: Collection[_T]
Expand Down Expand Up @@ -143,7 +143,7 @@ class DictWriter(Generic[_T]):
def writerow(self, rowdict: Mapping[_T, Any]) -> Any: ...
def writerows(self, rowdicts: Iterable[Mapping[_T, Any]]) -> None: ...
if sys.version_info >= (3, 12):
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

class Sniffer:
preferred: list[str]
Expand Down
6 changes: 3 additions & 3 deletions stdlib/ctypes/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ from _typeshed import StrPath, SupportsBool, SupportsLen
from ctypes._endian import BigEndianStructure as BigEndianStructure, LittleEndianStructure as LittleEndianStructure
from types import GenericAlias
from typing import Any, ClassVar, Final, Generic, Literal, TypeAlias, TypeVar, overload, type_check_only
from typing_extensions import Self, deprecated
from typing_extensions import Self, TypeForm, deprecated

if sys.platform == "win32":
from _ctypes import FormatError as FormatError, get_last_error as get_last_error, set_last_error as set_last_error
Expand Down Expand Up @@ -108,7 +108,7 @@ class LibraryLoader(Generic[_DLLT]):
def __getattr__(self, name: str) -> _DLLT: ...
def __getitem__(self, name: str) -> _DLLT: ...
def LoadLibrary(self, name: str) -> _DLLT: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

cdll: LibraryLoader[CDLL]
if sys.platform == "win32":
Expand Down Expand Up @@ -214,7 +214,7 @@ if sys.version_info >= (3, 14):
class py_object(_CanCastTo, _SimpleCData[_T]):
_type_: ClassVar[Literal["O"]]
if sys.version_info >= (3, 14):
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

class c_bool(_SimpleCData[bool]):
_type_: ClassVar[Literal["?"]]
Expand Down
4 changes: 2 additions & 2 deletions stdlib/dataclasses.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from builtins import type as Type # alias to avoid name clashes with fields nam
from collections.abc import Callable, Iterable, Mapping
from types import GenericAlias
from typing import Any, Final, Generic, Literal, Protocol, TypeVar, overload, type_check_only
from typing_extensions import Never, TypeIs
from typing_extensions import Never, TypeForm, TypeIs

_T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
Expand Down Expand Up @@ -212,7 +212,7 @@ class Field(Generic[_T]):
) -> None: ...

def __set_name__(self, owner: Type[Any], name: str) -> None: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

# NOTE: Actual return type is 'Field[_T]', but we want to help type checkers
# to understand the magic that happens at runtime.
Expand Down
3 changes: 2 additions & 1 deletion stdlib/difflib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import sys
from collections.abc import Callable, Iterable, Iterator, Sequence
from types import GenericAlias
from typing import Any, AnyStr, Generic, Literal, NamedTuple, TypeVar, overload
from typing_extensions import TypeForm

__all__ = [
"get_close_matches",
Expand Down Expand Up @@ -49,7 +50,7 @@ class SequenceMatcher(Generic[_T]):
def ratio(self) -> float: ...
def quick_ratio(self) -> float: ...
def real_quick_ratio(self) -> float: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
def __class_getitem__(cls, item: TypeForm[Any], /) -> GenericAlias: ...

@overload
def get_close_matches(word: AnyStr, possibilities: Iterable[AnyStr], n: int = 3, cutoff: float = 0.6) -> list[AnyStr]: ...
Expand Down
Loading
Loading