Wrapping methods of built-in dict
Steven D'Aprano
steven at REMOVE.THIS.cybersource.com.au
Wed May 20 22:31:29 EDT 2009
On Wed, 20 May 2009 18:42:38 -0700, shailesh wrote:
> The reason as far as I understand is that the methods on the built-in
> dict are not of MethodType or FunctionType
That seems to be true:
>>> type({}.get)
<type 'builtin_function_or_method'>
>>> type(dict.get)
<type 'method_descriptor'>
> so they are not included in
> the result of the inspect.getmembers call and are not wrapped.
But that isn't:
>>> zip(*inspect.getmembers(dict))[0] # extract the names only
('__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__',
'__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__',
'__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__',
'__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
'__setattr__', '__setitem__', '__str__', 'clear', 'copy', 'fromkeys',
'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys',
'pop', 'popitem', 'setdefault', 'update', 'values')
So the problem isn't directly with getmembers, but with the predicate
functions you have passed to it (inspect.isfunction and inspect.method).
Try inspect.ismethoddescriptor instead.
Hint: dir(inspect) and help(inspect.whatever) are useful :)
--
Steven
More information about the Python-list
mailing list