From 88145e76e3fbf283330c9cf8bb0d13bdc97a8114 Mon Sep 17 00:00:00 2001 From: Mehdi Drissi Date: Tue, 10 May 2022 21:32:41 -0700 Subject: [PATCH 1/2] Add __orig_bases__ to Generic --- stdlib/typing.pyi | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 5a8557f909e5..bebbf54a077a 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -49,7 +49,13 @@ def overload(func: _F) -> _F: ... # `_SpecialForm` objects in typing.py that are not used elswhere in the same file # do not need the default value assignment. Union: _SpecialForm = ... -Generic: _SpecialForm = ... + +class _GenericSpecialForm(_SpecialForm): + # More precisely this is tuple[TypeForm, ...] + # https://github.com/python/mypy/issues/9773 + __orig_bases__: ClassVar[tuple[type, ...]] + +Generic: _GenericSpecialForm = ... # Protocol is only present in 3.8 and later, but mypy needs it unconditionally Protocol: _SpecialForm = ... Callable: _SpecialForm = ... From 4faf48fbde094e50124438e44e057f178928d733 Mon Sep 17 00:00:00 2001 From: Mehdi Drissi Date: Tue, 10 May 2022 21:50:40 -0700 Subject: [PATCH 2/2] Remove final decorator for special form --- stdlib/typing.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 8146566f9bbd..4c3597469e95 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -493,7 +493,6 @@ class TypeVar: _promote = object() # N.B. Keep this definition in sync with typing_extensions._SpecialForm -@_final class _SpecialForm: def __getitem__(self, parameters: Any) -> object: ... if sys.version_info >= (3, 10): @@ -514,6 +513,7 @@ def overload(func: _F) -> _F: ... # do not need the default value assignment. Union: _SpecialForm = ... +@_final class _GenericSpecialForm(_SpecialForm): # More precisely this is tuple[TypeForm, ...] # https://github.com/python/mypy/issues/9773