[Python-checkins] bpo-39168: Remove the __new__ method of typing.Generic (GH-21327)

Zackery Spytz webhook-mailer at python.org
Sun Jul 5 01:07:49 EDT 2020


https://github.com/python/cpython/commit/7fed75597fac11f9a6c769e2b6c6548fe0e4049d
commit: 7fed75597fac11f9a6c769e2b6c6548fe0e4049d
branch: master
author: Zackery Spytz <zspytz at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-07-04T22:07:43-07:00
summary:

bpo-39168: Remove the __new__ method of typing.Generic (GH-21327)



Automerge-Triggered-By: @gvanrossum

files:
A Misc/NEWS.d/next/Library/2020-07-04-21-56-46.bpo-39168.DQWsXj.rst
M Lib/test/test_typing.py
M Lib/typing.py

diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index f429e883b5953..398add05a12b9 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -1417,8 +1417,6 @@ def test_basics(self):
     def test_generic_errors(self):
         T = TypeVar('T')
         S = TypeVar('S')
-        with self.assertRaises(TypeError):
-            Generic[T]()
         with self.assertRaises(TypeError):
             Generic[T][T]
         with self.assertRaises(TypeError):
diff --git a/Lib/typing.py b/Lib/typing.py
index f94996daebd6e..fd657caafee87 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -894,16 +894,6 @@ def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
     __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 0000000000000..667885eccd9c7
--- /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`.



More information about the Python-checkins mailing list