Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python2/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,9 @@ def test_new_no_args(self):
class A(Generic[T]):
pass

with self.assertRaises(TypeError):
A('foo')

class B(object):
def __new__(cls):
# call object
Expand Down
6 changes: 4 additions & 2 deletions python2/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,13 +1288,15 @@ def _generic_new(base_cls, cls, *args, **kwds):
# Assure type is erased on instantiation,
# but attempt to store it in __orig_class__
if cls.__origin__ is None:
if base_cls.__new__ is object.__new__:
if (base_cls.__new__ is object.__new__ and
cls.__init__ is not object.__init__):
return base_cls.__new__(cls)
else:
return base_cls.__new__(cls, *args, **kwds)
else:
origin = cls._gorg
if base_cls.__new__ is object.__new__:
if (base_cls.__new__ is object.__new__ and
cls.__init__ is not object.__init__):
obj = base_cls.__new__(origin)
else:
obj = base_cls.__new__(origin, *args, **kwds)
Expand Down
3 changes: 3 additions & 0 deletions src/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,9 @@ def test_new_no_args(self):
class A(Generic[T]):
pass

with self.assertRaises(TypeError):
A('foo')

class B:
def __new__(cls):
# call object
Expand Down
6 changes: 4 additions & 2 deletions src/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,13 +1182,15 @@ def _generic_new(base_cls, cls, *args, **kwds):
# Assure type is erased on instantiation,
# but attempt to store it in __orig_class__
if cls.__origin__ is None:
if base_cls.__new__ is object.__new__:
if (base_cls.__new__ is object.__new__ and
cls.__init__ is not object.__init__):
return base_cls.__new__(cls)
else:
return base_cls.__new__(cls, *args, **kwds)
else:
origin = cls._gorg
if base_cls.__new__ is object.__new__:
if (base_cls.__new__ is object.__new__ and
cls.__init__ is not object.__init__):
obj = base_cls.__new__(origin)
else:
obj = base_cls.__new__(origin, *args, **kwds)
Expand Down