This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients jdemeyer, scoder, steven.daprano
Date 2017-04-14.14:25:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1492179944.38.0.630206457082.issue30071@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-04-14 14:25:44steven.dapranosetrecipients: + steven.daprano, scoder, jdemeyer
2017-04-14 14:25:44steven.dapranosetmessageid: <1492179944.38.0.630206457082.issue30071@psf.upfronthosting.co.za>
2017-04-14 14:25:44steven.dapranolinkissue30071 messages
2017-04-14 14:25:43steven.dapranocreate