diff --git a/Lib/inspect.py b/Lib/inspect.py index d6bd8cd..b1a2cd2 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1528,6 +1528,12 @@ def signature(obj): init = _get_user_defined_method(obj, '__init__') if init is not None: sig = signature(init) + + if sig is None and obj is not object and type not in obj.__mro__: + # We have a class (not metaclass), but no user-defined + # __init__ or __new__ for it + return Signature() + elif not isinstance(obj, _NonUserDefinedCallables): # An object with __call__ # We also check that the 'obj' is not an instance of diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 1bfe724..798bf46 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -1964,6 +1964,12 @@ class TestSignatureObject(unittest.TestCase): ('bar', 2, ..., "keyword_only")), ...)) + # Test classes without user-defined __init__ or __new__ + class C: pass + self.assertEqual(self.signature(C), ((), ...)) + class D(C): pass + self.assertEqual(self.signature(D), self.signature(C)) + def test_signature_on_callable_objects(self): class Foo: def __call__(self, a):