[issue20309] Not all method descriptors are callable
eryksun
report at bugs.python.org
Thu Apr 17 10:44:47 CEST 2014
eryksun added the comment:
classmethod_descriptor instances such as vars(dict)['fromkeys'] are callable. The first argument has to be a subclass of __objclass__:
>>> vars(dict)['fromkeys'].__objclass__
<class 'dict'>
Calling the descriptor creates a bound built-in method; slices the args to remove the class; and calls it with the args and kwds.
>>> vars(dict)['fromkeys'](dict, 'abc')
{'a': None, 'b': None, 'c': None}
source: classmethoddescr_call
http://hg.python.org/cpython/file/04f714765c13/Objects/descrobject.c#l256
While the classmethod and staticmethod types that are defined in funcobject.c aren't callable, they do expose a __func__ member.
----------
nosy: +eryksun
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20309>
_______________________________________
More information about the Python-bugs-list
mailing list