diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/inspect.py | 4 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 7 |
2 files changed, 11 insertions, 0 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index 4ac76b1..b9cdcc2 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1939,6 +1939,10 @@ def _signature_from_callable(obj, *, pass else: if sig is not None: + if not isinstance(sig, Signature): + raise TypeError( + 'unexpected object {!r} in __signature__ ' + 'attribute'.format(sig)) return sig try: diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 7ad190b..63bdb15 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -3136,6 +3136,13 @@ class TestMain(unittest.TestCase): self.assertEqual(lines[:-1], inspect.getsource(module).splitlines()) self.assertEqual(err, b'') + def test_custom_getattr(self): + def foo(): + pass + foo.__signature__ = 42 + with self.assertRaises(TypeError): + inspect.signature(foo) + @unittest.skipIf(ThreadPoolExecutor is None, 'threads required to test __qualname__ for source files') def test_qualname_source(self): |