From 28abff1eb3c477d6b5f85224f5e1301352779089 Mon Sep 17 00:00:00 2001 From: Mantas <56790921+mantasu@users.noreply.github.com> Date: Thu, 21 Aug 2025 15:21:11 +0100 Subject: [PATCH] typing: make Generic definition reflect runtime (#14583) Co-authored-by: Alex Waygood --- stdlib/@tests/stubtest_allowlists/common.txt | 1 - stdlib/typing.pyi | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index 3de125744..4462ada91 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -466,7 +466,6 @@ typing._Final.__init_subclass__ typing\.Protocol typing(_extensions)?\._TypedDict typing(_extensions)?\.Any.* -typing(_extensions)?\.Generic typing(_extensions)?\.TypedDict typing_extensions\.ParamSpec.* typing_extensions\.TypeVar.* diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 7d048a13c..d08407ecd 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -235,7 +235,6 @@ class _SpecialForm(_Final): def __ror__(self, other: Any) -> _SpecialForm: ... Union: _SpecialForm -Generic: _SpecialForm Protocol: _SpecialForm Callable: _SpecialForm Type: _SpecialForm @@ -440,6 +439,20 @@ Annotated: _SpecialForm # Predefined type variables. AnyStr = TypeVar("AnyStr", str, bytes) # noqa: Y001 +@type_check_only +class _Generic: + if sys.version_info < (3, 12): + __slots__ = () + + if sys.version_info >= (3, 10): + @classmethod + def __class_getitem__(cls, args: TypeVar | ParamSpec | tuple[TypeVar | ParamSpec, ...]) -> _Final: ... + else: + @classmethod + def __class_getitem__(cls, args: TypeVar | tuple[TypeVar, ...]) -> _Final: ... + +Generic: type[_Generic] + class _ProtocolMeta(ABCMeta): if sys.version_info >= (3, 12): def __init__(cls, *args: Any, **kwargs: Any) -> None: ...