What is the method-wrapper type in Python 3? If I define a class like so:
class Foo(object):
def __init__(self, val):
self.val = val
def __eq__(self, other):
return self.val == other.val
And then do:
Foo(42).__eq__
I get:
<bound method Foo.__eq__ of <__main__.Foo object at 0x10121d0>>
But if I do (in Python 3 ):
Foo(42).__ne__
I get:
<method-wrapper '__ne__' of Foo object at 0x1073e50>
What is a "method-wrapper" type?
Edit: sorry to be more accurate: class method-wrapper
is the type of __ne__
, as if I do:
>>> type(Foo(42).__ne__)
<class 'method-wrapper'>
Whereas the type of __eq__
is:
>>> type(Foo(42).__eq__)
<class 'method'>
Furthermore method-wrapper
seems to be the type of any undefined magic method on a class (so __le__
, __repr__
, __str__
etc if not explicitly defined will also have this type).
What I am interested in is how the method-wrapper
class is used by Python. Are all "default implementations" of methods on a class just instances of this type?