From 0bd1dffaf1e6eb59e330279fe8898c2d25de7922 Mon Sep 17 00:00:00 2001 From: jorenham Date: Sun, 4 May 2025 18:29:51 +0200 Subject: [PATCH] generic `GenericAlias` --- stdlib/types.pyi | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/stdlib/types.pyi b/stdlib/types.pyi index fe443be27121..a1312447cb9e 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -16,8 +16,8 @@ from collections.abc import ( ValuesView, ) from importlib.machinery import ModuleSpec -from typing import Any, ClassVar, Literal, TypeVar, final, overload -from typing_extensions import ParamSpec, Self, TypeAliasType, TypeVarTuple, deprecated +from typing import Any, ClassVar, Generic, Literal, final, overload +from typing_extensions import ParamSpec, Self, TypeAliasType, TypeVar, TypeVarTuple, deprecated __all__ = [ "FunctionType", @@ -642,14 +642,17 @@ def coroutine(func: Callable[_P, Generator[Any, Any, _R]]) -> Callable[_P, Await @overload def coroutine(func: _Fn) -> _Fn: ... -class GenericAlias: +# typically a type or type expression +_OriginT_co = TypeVar("_OriginT_co", bound=type | TypeAliasType, default=type | TypeAliasType, covariant=True) + +class GenericAlias(Generic[_OriginT_co]): @property - def __origin__(self) -> type | TypeAliasType: ... + def __origin__(self) -> _OriginT_co: ... @property def __args__(self) -> tuple[Any, ...]: ... @property def __parameters__(self) -> tuple[Any, ...]: ... - def __new__(cls, origin: type, args: Any, /) -> Self: ... + def __new__(cls, origin: _OriginT_co, args: Any, /) -> Self: ... def __getitem__(self, typeargs: Any, /) -> GenericAlias: ... def __eq__(self, value: object, /) -> bool: ... def __hash__(self) -> int: ...