Message181937
In my opinion, the Python 2.7 results are wrong.
In Python 2.7, inspect.ismethod returns True for both bound and unbound methods -- ie., is broken according to the documentation. As a workaround, I'm using:
def is_bound_method(obj):
return hasattr(obj, '__self__') and obj.__self__ is not None
is_bound_method also works for methods of classes implemented in C, e.g., int:
>>> a = 1
>>> is_bound_method(a.__add__)
True
>>> is_bound_method(int.__add__)
False
But is not very useful in that case because inspect.getargspec does not work for functions implemented in C.
is_bound_method works unchanged in Python 3, but as noted above, in Python 3, inspect.ismethod properly distinguishes between bound and unbound methods, so it is not necessary. |
|
Date |
User |
Action |
Args |
2013-02-12 00:07:09 | gregcouch | set | recipients:
+ gregcouch, ezio.melotti, eric.araujo, chris.jerdonek, docs@python, federico.reghenzani, wdanilo |
2013-02-12 00:07:09 | gregcouch | set | messageid: <1360627629.48.0.628654026974.issue16851@psf.upfronthosting.co.za> |
2013-02-12 00:07:09 | gregcouch | link | issue16851 messages |
2013-02-12 00:07:09 | gregcouch | create | |
|