diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2014-01-29 15:52:57 (GMT) |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2014-01-29 15:52:57 (GMT) |
commit | 76c6c593ed0e85332a3d320c57cf032d22410426 (patch) | |
tree | 9fe6b60ac1d4275bf44ca71936da0d827b5f84f3 | |
parent | b77511da9257bae4082556e0235b23d008dfb789 (diff) | |
download | cpython-76c6c593ed0e85332a3d320c57cf032d22410426.zip cpython-76c6c593ed0e85332a3d320c57cf032d22410426.tar.gz cpython-76c6c593ed0e85332a3d320c57cf032d22410426.tar.bz2 |
inspect.signature: Add support for decorated (wrapped) builtins #20425
-rw-r--r-- | Lib/inspect.py | 6 | ||||
-rw-r--r-- | Lib/test/test_inspect.py | 15 |
2 files changed, 18 insertions, 3 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index fefcddb..f0c1247 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1530,9 +1530,6 @@ def signature(obj): if not callable(obj): raise TypeError('{!r} is not a callable object'.format(obj)) - if _signature_is_builtin(obj): - return Signature.from_builtin(obj) - if isinstance(obj, types.MethodType): # In this case we skip the first parameter of the underlying # function (usually `self` or `cls`). @@ -1570,6 +1567,9 @@ def signature(obj): return sig.replace(parameters=new_params) + if _signature_is_builtin(obj): + return Signature.from_builtin(obj) + if isinstance(obj, types.FunctionType): return Signature.from_function(obj) diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 2ef3ca2..4f19f29 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -1655,6 +1655,21 @@ class TestSignatureObject(unittest.TestCase): __call__ = type test_callable(ThisWorksNow()) + @unittest.skipIf(MISSING_C_DOCSTRINGS, + "Signature information for builtins requires docstrings") + def test_signature_on_decorated_builtins(self): + func = _testcapi.docstring_with_signature_with_defaults + + def decorator(func): + @functools.wraps(func) + def wrapper(*args, **kwargs) -> int: + return func(*args, **kwargs) + return wrapper + + decorated_func = decorator(func) + + self.assertEqual(inspect.signature(func), + inspect.signature(decorated_func)) def test_signature_on_builtins_no_signature(self): with self.assertRaisesRegex(ValueError, 'no signature found for builtin'): |