Author terry.reedy
Recipients jdemeyer, r.david.murray, scoder, serhiy.storchaka, steven.daprano, terry.reedy
Date 2017-04-15.20:04:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
inspect.getargspec is deprecated in favor of .getfullargspec and .signature and is implemented in with .getfullargspec.  This, in turn, calls ._signature_from_callable which ultimately looks for (perhaps after recursive unwrap calls) obj.__signature__.  So I expect that the case you 'care most about' already works.  True?

It appears that .signature is intended to work for cython functions via the following helper function. Its code is somewhat awkward and tests that the object has needed attributes with needed types.

def _signature_is_functionlike(obj):
    """Private helper to test if `obj` is a duck type of FunctionType.
    A good example of such objects are functions compiled with
    Cython, which have all attributes that a pure Python function
    would have, but have their code statically compiled.

That does leave cases like the inspect.getfile code you quoted.  It could be fixed with some fiddly code, but there would still be .getclosurevariables and a couple of other uses of isfunction to review.

I reviewed the function and code attributes listed in
and I think the necessary differences a function compiled by CPython and anything else are limited to the code object.

Proposal: for a cleaner solution, define a 'mincode' base class that lacks, for instance, co_code, co_consts, co_flags, co_lnotab, and co_stacksize.  Make code a subclass of this.  Define 'minfunction' as a function whose __code__ is a mincode.  Make function a subclass of this.  Define 'isminfunction' and replace 'isfunction' where a mincode is sufficient.  This might allow, for instance, _signature_is_functionlike to be removed.

Details should perhaps be specified in a relatively short PEP.  Discussion could maybe continue on python-ideas.
Date User Action Args
2017-04-15 20:04:44terry.reedysetrecipients: + terry.reedy, scoder, steven.daprano, r.david.murray, serhiy.storchaka, jdemeyer
2017-04-15 20:04:44terry.reedysetmessageid: <>
2017-04-15 20:04:44terry.reedylinkissue30071 messages
2017-04-15 20:04:43terry.reedycreate