cpython: 32a660a52aae (original) (raw)

Mercurial > cpython

changeset 88866:32a660a52aae

inspect.signature: Support duck-types of Python functions (Cython, for instance) #17159 [#17159]

Yury Selivanov yselivanov@sprymix.com
date Fri, 31 Jan 2014 14:48:37 -0500
parents d0f95094033d
children 8a91132ed6aa
files Doc/whatsnew/3.4.rst Lib/inspect.py Lib/test/test_inspect.py Misc/NEWS
diffstat 4 files changed, 97 insertions(+), 2 deletions(-)[+] [-] Doc/whatsnew/3.4.rst 4 Lib/inspect.py 32 Lib/test/test_inspect.py 60 Misc/NEWS 3

line wrap: on

line diff

--- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -793,6 +793,10 @@ callables that follow __signature__ recommended to update your code to use :func:~inspect.signature directly. (Contributed by Yury Selivanov in :issue:17481) +:func:~inspect.signature now supports duck types of CPython functions, +which adds support for functions compiled with Cython. (Contributed +by Stefan Behnel and Yury Selivanov in :issue:17159) + logging -------

--- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1601,6 +1601,30 @@ def _signature_is_builtin(obj): obj in (type, object)) +def _signature_is_functionlike(obj):

+

+

+

+ + def _signature_get_bound_param(spec): # Internal helper to get first parameter name from a # text_signature of a builtin method, which should @@ -1670,7 +1694,9 @@ def signature(obj): if _signature_is_builtin(obj): return Signature.from_builtin(obj)

if isinstance(obj, functools.partial): @@ -2071,7 +2097,9 @@ class Signature: def from_function(cls, func): '''Constructs Signature for the given python function'''

Parameter = cls._parameter_cls

--- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -1740,6 +1740,66 @@ class TestSignatureObject(unittest.TestC with self.assertRaisesRegex(TypeError, 'is not a Python builtin'): inspect.Signature.from_builtin(42)

+

+

+

+

+

+

+

+

+

+

+

+

+

+ def test_signature_on_method(self): class Test: def init(*args):

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,9 @@ Core and Builtins Library ------- +- Issue #17159: inspect.signature now accepts duck types of functions,