]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39168: Remove the __new__ method of typing.Generic (GH-21327)
authorZackery Spytz <zspytz@gmail.com>
Sun, 5 Jul 2020 05:07:43 +0000 (23:07 -0600)
committerGitHub <noreply@github.com>
Sun, 5 Jul 2020 05:07:43 +0000 (22:07 -0700)
Automerge-Triggered-By: @gvanrossum
Lib/test/test_typing.py
Lib/typing.py
Misc/NEWS.d/next/Library/2020-07-04-21-56-46.bpo-39168.DQWsXj.rst [new file with mode: 0644]

index f429e883b595384dd62e1a83ca0062461e1a0e61..398add05a12b992d4815a9960698dd338a9aae95 100644 (file)
@@ -1417,8 +1417,6 @@ class GenericTests(BaseTestCase):
     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):
index f94996daebd6ed8ce05c7ba32bae1a24a93fab6d..fd657caafee870f59ad112f97ff6e80d084e2319 100644 (file)
@@ -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 (file)
index 0000000..667885e
--- /dev/null
@@ -0,0 +1 @@
+Remove the ``__new__`` method of :class:`typing.Generic`.