Skip to content

Commit 28abff1

Browse files
mantasuAlexWaygood
andauthored
typing: make Generic definition reflect runtime (python#14583)
Co-authored-by: Alex Waygood <[email protected]>
1 parent 7c9cc3b commit 28abff1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

stdlib/@tests/stubtest_allowlists/common.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ typing._Final.__init_subclass__
466466
typing\.Protocol
467467
typing(_extensions)?\._TypedDict
468468
typing(_extensions)?\.Any.*
469-
typing(_extensions)?\.Generic
470469
typing(_extensions)?\.TypedDict
471470
typing_extensions\.ParamSpec.*
472471
typing_extensions\.TypeVar.*

stdlib/typing.pyi

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ class _SpecialForm(_Final):
235235
def __ror__(self, other: Any) -> _SpecialForm: ...
236236

237237
Union: _SpecialForm
238-
Generic: _SpecialForm
239238
Protocol: _SpecialForm
240239
Callable: _SpecialForm
241240
Type: _SpecialForm
@@ -440,6 +439,20 @@ Annotated: _SpecialForm
440439
# Predefined type variables.
441440
AnyStr = TypeVar("AnyStr", str, bytes) # noqa: Y001
442441

442+
@type_check_only
443+
class _Generic:
444+
if sys.version_info < (3, 12):
445+
__slots__ = ()
446+
447+
if sys.version_info >= (3, 10):
448+
@classmethod
449+
def __class_getitem__(cls, args: TypeVar | ParamSpec | tuple[TypeVar | ParamSpec, ...]) -> _Final: ...
450+
else:
451+
@classmethod
452+
def __class_getitem__(cls, args: TypeVar | tuple[TypeVar, ...]) -> _Final: ...
453+
454+
Generic: type[_Generic]
455+
443456
class _ProtocolMeta(ABCMeta):
444457
if sys.version_info >= (3, 12):
445458
def __init__(cls, *args: Any, **kwargs: Any) -> None: ...

0 commit comments

Comments
 (0)