Message209896
Hmm, I now notice that I was mistaken about this working:
'''
import inspect
def test_isfunction():
"""
>>> test_isfunction()
True
"""
return inspect.isfunction(test_isfunction)
'''
It only worked in Cython's test suite because its test runner monkey patches "inspect.isfunction", and I had completely forgotten about it. Sorry for the confusion.
The thing is that Cython's function type isn't really a Python function (obviously), it inherits from PyCFunction, so it should return True for isbuiltin(). A problem on our side prevented that. If I fix it up, then the newly added duck-typing code actually ends up not being used, because signature() tests for isbuiltin() first and runs into Signature.from_builtin(), which is the Argument Clinic code path that expects a textual signature representation. Cython functions don't have that, because they are compatible with Python functions.
This situation could be helped in inspect.signature() by reversing the test order, i.e. by changing this code
if _signature_is_builtin(obj):
return Signature.from_builtin(obj)
if isfunction(obj) or _signature_is_functionlike(obj):
# If it's a pure Python function, or an object that is duck type
# of a Python function (Cython functions, for instance), then:
return Signature.from_function(obj)
into this:
if isfunction(obj) or _signature_is_functionlike(obj):
# If it's a pure Python function, or an object that is duck type
# of a Python function (Cython functions, for instance), then:
return Signature.from_function(obj)
if _signature_is_builtin(obj):
return Signature.from_builtin(obj)
Would this be ok?
I would also argue that the implementation of _signature_is_builtin() is, well, not ideal, because what it should test for according to the comment at the top of the function is the existance of "__text_signature__". Instead, it does several type tests, one of which goes wrong in this case. |
|
Date |
User |
Action |
Args |
2014-02-01 16:20:48 | scoder | set | recipients:
+ scoder, terry.reedy, ncoghlan, pitrou, larry, benjamin.peterson, eric.araujo, python-dev, yselivanov |
2014-02-01 16:20:48 | scoder | set | messageid: <1391271648.36.0.912009382575.issue17159@psf.upfronthosting.co.za> |
2014-02-01 16:20:48 | scoder | link | issue17159 messages |
2014-02-01 16:20:47 | scoder | create | |
|