Signature
def __get__(self, obj, objtype=None):
says it objtypeis an optional argument. If __get__called with only one argument, it objtypewill be set to None.
, Foo Bar, foo.baz :
class Foo(object):
pass
class Bar(object):
def baz(self):
print('Hi')
foo = Foo()
foo.baz = Bar.baz.__get__(foo)
print(foo.__dict__)
foo.baz()
__get__,
foo.baz = Bar.baz.__get__(foo, foo.__class__)
foo.baz - unbound Bar.baz foo.baz()
TypeError: unbound method baz() must be called with Bar instance as first argument (got nothing instead)
, Python3 unbound method . , , obj . , Python3,
1-, 2- foo.baz .