Skip to content

Commit b551e9f

Browse files
authored
Fix a bug in Generic.__new__ (GH-6758)
1 parent df00f04 commit b551e9f

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Lib/test/test_typing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,9 @@ def test_new_no_args(self):
13671367
class A(Generic[T]):
13681368
pass
13691369

1370+
with self.assertRaises(TypeError):
1371+
A('foo')
1372+
13701373
class B:
13711374
def __new__(cls):
13721375
# call object

Lib/typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ def __new__(cls, *args, **kwds):
836836
if cls is Generic:
837837
raise TypeError("Type Generic cannot be instantiated; "
838838
"it can be used only as a base class")
839-
if super().__new__ is object.__new__:
839+
if super().__new__ is object.__new__ and cls.__init__ is not object.__init__:
840840
obj = super().__new__(cls)
841841
else:
842842
obj = super().__new__(cls, *args, **kwds)

0 commit comments

Comments
 (0)