From b551e9f0ff25018a5606465003e2c51c04f693a3 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Thu, 10 May 2018 23:10:10 -0400 Subject: [PATCH] Fix a bug in Generic.__new__ (GH-6758) --- Lib/test/test_typing.py | 3 +++ Lib/typing.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 46bab5eba6d..314716cd7de 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -1367,6 +1367,9 @@ class GenericTests(BaseTestCase): class A(Generic[T]): pass + with self.assertRaises(TypeError): + A('foo') + class B: def __new__(cls): # call object diff --git a/Lib/typing.py b/Lib/typing.py index 89b73db1583..8025dfd9326 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -836,7 +836,7 @@ class Generic: if cls is Generic: raise TypeError("Type Generic cannot be instantiated; " "it can be used only as a base class") - if super().__new__ is object.__new__: + if super().__new__ is object.__new__ and cls.__init__ is not object.__init__: obj = super().__new__(cls) else: obj = super().__new__(cls, *args, **kwds)