[issue30071] Duck-typing inspect.isfunction()

2018-04-04 Thread Jeroen Demeyer
Jeroen Demeyer added the comment: Superseded by https://www.python.org/dev/peps/pep-0575/ -- stage: test needed -> resolved status: open -> closed ___ Python tracker

[issue30071] Duck-typing inspect.isfunction()

2018-03-22 Thread Jeroen Demeyer
Jeroen Demeyer added the comment: See https://mail.python.org/pipermail/python-ideas/2018-March/049398.html -- ___ Python tracker

[issue30071] Duck-typing inspect.isfunction()

2017-04-19 Thread Jeroen Demeyer
Jeroen Demeyer added the comment: > So I expect that the case you 'care most about' already works. Yes, it works. That's the most ironic part of this issue: getfullargspec(func) works but packages like Sphinx will not call getfullargspec(func) because they do not detect that "func" is

[issue30071] Duck-typing inspect.isfunction()

2017-04-15 Thread Terry J. Reedy
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

[issue30071] Duck-typing inspect.isfunction()

2017-04-15 Thread Jeroen Demeyer
Jeroen Demeyer added the comment: For the record: the __code__ attribute of a Cython function is a real "code" object (the same type as the __code__ attribute of a Python function). Of course not all fields are relevant, for example co_code is empty. So I think it's clear that Cython tries

[issue30071] Duck-typing inspect.isfunction()

2017-04-15 Thread Jeroen Demeyer
Jeroen Demeyer added the comment: > As indicated above, perfect emulation seems impossible for Cython or any > other external compiler that does not use the same bytecode. True, Cython functions are not implemented using Python bytecode, so perfect emulation is impossible. The use case I care

[issue30071] Duck-typing inspect.isfunction()

2017-04-15 Thread Terry J. Reedy
Terry J. Reedy added the comment: inspect.isfunction(object) is documented to Return true if the object is a Python function, which includes functions created by a lambda expression. This is currently implemented as "isinstance(object, types.FunctionType)". The docs usually regard a

[issue30071] Duck-typing inspect.isfunction()

2017-04-14 Thread Jeroen Demeyer
Jeroen Demeyer added the comment: At the very least, the inspect module should use more duck-typing internally. For example, consider this code from "getfile": if ismethod(object): object = object.__func__ if isfunction(object): object = object.__code__ if

[issue30071] Duck-typing inspect.isfunction()

2017-04-14 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: __code__ is not enough for quacking as a function. Different code can expect other function attributes (for example __name__, __qualname__ and __module__). See also issue8488. inspect.isroutine() and inspect.ismethoddescriptor() return True for some

[issue30071] Duck-typing inspect.isfunction()

2017-04-14 Thread R. David Murray
R. David Murray added the comment: The python standard library makes extensive use of duck typing. Duck typing is a pretty fundamental part of the design of Python, IMO. Even the ABC module does a bunch of duck typing, rather than requiring strict subclassing or registration. I think the

[issue30071] Duck-typing inspect.isfunction()

2017-04-14 Thread Jeroen Demeyer
Jeroen Demeyer added the comment: > If inspect reports something is a duck, it should be an actual duck, not just > something that quacks. The problem is that some Python packages (Sphinx and IPython for example) really need to know whether it quacks. And the only tool they have is

[issue30071] Duck-typing inspect.isfunction()

2017-04-14 Thread Steven D'Aprano
Steven D'Aprano added the comment: Duck typing is not something that "Python" does, it is a style of programming done by Python programmers. You wouldn't expect isinstance() to try to "duck type", and likewise the inspect module should be precise about what it is inspecting. If inspect

[issue30071] Duck-typing inspect.isfunction()

2017-04-14 Thread Jeroen Demeyer
Changes by Jeroen Demeyer : -- keywords: +patch Added file: http://bugs.python.org/file46803/isfunction.patch ___ Python tracker

[issue30071] Duck-typing inspect.isfunction()

2017-04-14 Thread Jeroen Demeyer
New submission from Jeroen Demeyer: Python is supposed to encourage duck-typing, but the "inspect" module doesn't follow this advice. A particular problem is that Cython functions are not recognized by the inspect module to be functions: