From 7fed75597fac11f9a6c769e2b6c6548fe0e4049d Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Sat, 4 Jul 2020 23:07:43 -0600 Subject: bpo-39168: Remove the __new__ method of typing.Generic (GH-21327) Automerge-Triggered-By: @gvanrossum --- Lib/test/test_typing.py | 2 -- Lib/typing.py | 10 ---------- .../next/Library/2020-07-04-21-56-46.bpo-39168.DQWsXj.rst | 1 + 3 files changed, 1 insertion(+), 12 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2020-07-04-21-56-46.bpo-39168.DQWsXj.rst diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index f429e88..398add0 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -1418,8 +1418,6 @@ class GenericTests(BaseTestCase): T = TypeVar('T') S = TypeVar('S') with self.assertRaises(TypeError): - Generic[T]() - with self.assertRaises(TypeError): Generic[T][T] with self.assertRaises(TypeError): Generic[T][S] diff --git a/Lib/typing.py b/Lib/typing.py index f94996d..fd657ca 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -894,16 +894,6 @@ class Generic: __slots__ = () _is_protocol = False - def __new__(cls, *args, **kwds): - if cls in (Generic, Protocol): - raise TypeError(f"Type {cls.__name__} cannot be instantiated; " - "it can be used only as a base class") - if super().__new__ is object.__new__ and cls.__init__ is not object.__init__: - obj = super().__new__(cls) - else: - obj = super().__new__(cls, *args, **kwds) - return obj - @_tp_cache def __class_getitem__(cls, params): if not isinstance(params, tuple): diff --git a/Misc/NEWS.d/next/Library/2020-07-04-21-56-46.bpo-39168.DQWsXj.rst b/Misc/NEWS.d/next/Library/2020-07-04-21-56-46.bpo-39168.DQWsXj.rst new file mode 100644 index 0000000..667885e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-07-04-21-56-46.bpo-39168.DQWsXj.rst @@ -0,0 +1 @@ +Remove the ``__new__`` method of :class:`typing.Generic`. -- cgit v0.12