]> granicus.if.org Git - python/commitdiff
Fix a bug in Generic.__new__ (GH-6758)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 11 May 2018 03:30:47 +0000 (20:30 -0700)
committerGitHub <noreply@github.com>
Fri, 11 May 2018 03:30:47 +0000 (20:30 -0700)
(cherry picked from commit b551e9f0ff25018a5606465003e2c51c04f693a3)

Co-authored-by: Ivan Levkivskyi <levkivskyi@gmail.com>
Lib/test/test_typing.py
Lib/typing.py

index 46bab5eba6db8b5f20c968196d868d35711bd4d1..314716cd7de354502d325ec1779642f2478c868e 100644 (file)
@@ -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
index 89b73db158379ecfe0ad68ba4fa891f947c142e5..8025dfd932624b651798105bcb2bb9d31cba2828 100644 (file)
@@ -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)