[issue27901] DOC: inspect.ismethod returns different results on the same basic code between Python2.7 Python3.5

Andrei Kulakov report at bugs.python.org
Mon Jun 7 14:54:15 EDT 2021


Andrei Kulakov <andrei.avk at gmail.com> added the comment:

The data model docs still have 2 references to unbound methods:

For callables, it may indicate that an instance of the given type (or a subclass) is expected or required as the first positional argument (for example, CPython sets this attribute for unbound methods that are implemented in C).
...
Incorrectly attempting to invoke an unbound method of a class in this way is sometimes referred to as ‘metaclass confusion’, and is avoided by bypassing the instance when looking up special methods:

So the concept of unbound methods is still valid, and in addition I would expect that majority of users think of a method defined in a class as a "method" rather than "function defined in class that will become a method" - perhaps because the former is much shorter ;-)

Therefore inspect.ismethod() returning False can easily cause confusion.

I think it might be worth adding this note to `ismethod` docs, something like:

"While the term 'unbound method' is commonly used for functions defined on class objects, from the point of view of `inspect` it is not a method because the object itself is just a plain function."

I can make a PR if this sounds reasonable?

----------
nosy: +andrei.avk

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue27901>
_______________________________________


More information about the Python-bugs-list mailing list