Skip to content

Commit 5a13849

Browse files
bpo-39168: Remove the __new__ method of typing.Generic (GH-21327)
Automerge-Triggered-By: @gvanrossum (cherry picked from commit 7fed755) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
1 parent 16f4517 commit 5a13849

File tree

3 files changed

+1
-12
lines changed

3 files changed

+1
-12
lines changed

Lib/test/test_typing.py

-2
Original file line numberDiff line numberDiff line change
@@ -1417,8 +1417,6 @@ def test_basics(self):
14171417
def test_generic_errors(self):
14181418
T = TypeVar('T')
14191419
S = TypeVar('S')
1420-
with self.assertRaises(TypeError):
1421-
Generic[T]()
14221420
with self.assertRaises(TypeError):
14231421
Generic[T][T]
14241422
with self.assertRaises(TypeError):

Lib/typing.py

-10
Original file line numberDiff line numberDiff line change
@@ -894,16 +894,6 @@ def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
894894
__slots__ = ()
895895
_is_protocol = False
896896

897-
def __new__(cls, *args, **kwds):
898-
if cls in (Generic, Protocol):
899-
raise TypeError(f"Type {cls.__name__} cannot be instantiated; "
900-
"it can be used only as a base class")
901-
if super().__new__ is object.__new__ and cls.__init__ is not object.__init__:
902-
obj = super().__new__(cls)
903-
else:
904-
obj = super().__new__(cls, *args, **kwds)
905-
return obj
906-
907897
@_tp_cache
908898
def __class_getitem__(cls, params):
909899
if not isinstance(params, tuple):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove the ``__new__`` method of :class:`typing.Generic`.

0 commit comments

Comments
 (0)