Unverified Kaydet (Commit) b551e9f0 authored tarafından Ivan Levkivskyi's avatar Ivan Levkivskyi Kaydeden (comit) GitHub

Fix a bug in Generic.__new__ (GH-6758)

üst df00f048
...@@ -1367,6 +1367,9 @@ class GenericTests(BaseTestCase): ...@@ -1367,6 +1367,9 @@ class GenericTests(BaseTestCase):
class A(Generic[T]): class A(Generic[T]):
pass pass
with self.assertRaises(TypeError):
A('foo')
class B: class B:
def __new__(cls): def __new__(cls):
# call object # call object
......
...@@ -836,7 +836,7 @@ class Generic: ...@@ -836,7 +836,7 @@ class Generic:
if cls is Generic: if cls is Generic:
raise TypeError("Type Generic cannot be instantiated; " raise TypeError("Type Generic cannot be instantiated; "
"it can be used only as a base class") "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) obj = super().__new__(cls)
else: else:
obj = super().__new__(cls, *args, **kwds) obj = super().__new__(cls, *args, **kwds)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment