Terry J. Reedy added the comment:

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
https://docs.python.org/3/library/inspect.html#types-and-members
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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30071>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to