diff --git a/python2/test_typing.py b/python2/test_typing.py index f1f4adcbc..ff15c3abf 100644 --- a/python2/test_typing.py +++ b/python2/test_typing.py @@ -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 diff --git a/python2/typing.py b/python2/typing.py index 98efb244e..4d999d0a3 100644 --- a/python2/typing.py +++ b/python2/typing.py @@ -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) diff --git a/src/test_typing.py b/src/test_typing.py index 8b154d233..ac7390667 100644 --- a/src/test_typing.py +++ b/src/test_typing.py @@ -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 diff --git a/src/typing.py b/src/typing.py index 0595e7e34..7c0b1f644 100644 --- a/src/typing.py +++ b/src/typing.py @@ -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)