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 reports something is a duck, it should be an actual 
duck, not just something that quacks.

I'm not sure that the CPython inspect module should care about Cython objects. 
I don't think that Cython functions should count as Python functions, I think 
they are different kinds of callables.

But even if we decide that Cython function should be recognised by 
inspect.isfunction(), I don't think your patch is the right way to deal with 
it. Not every object with a __code__ attribute is a function.

py> from types import SimpleNamespace
py> x = SimpleNamespace(__code__=1, spam=2)
py> '__code__' in dir(x)
True

Your patch would wrongly detect x as a function when it isn't even callable.

----------
nosy: +steven.daprano

_______________________________________
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