mirror of
https://github.com/python/cpython.git
synced 2025-10-02 13:22:19 +00:00
Fix a bug in Generic.__new__ (GH-6758)
(cherry picked from commit b551e9f0ff
)
Co-authored-by: Ivan Levkivskyi <levkivskyi@gmail.com>
This commit is contained in:
parent
22df4187c3
commit
c5444b3556
2 changed files with 4 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue