What arguments do types.MethodType
expect and what does it return?
https://docs.python.org/3.6/library/types.html doesn't say more about it:
types.MethodType
The type of methods of user-defined class instances.
For an example, from https://docs.python.org/3.6/howto/descriptor.html
To support method calls, functions include the
__get__()
method for binding methods during attribute access. This means that all functions are non-data descriptors which return bound or unbound methods depending whether they are invoked from an object or a class. In pure python, it works like this:class Function(object): . . . def __get__(self, obj, objtype=None): "Simulate func_descr_get() in Objects/funcobject.c" if obj is None: return self return types.MethodType(self, obj)
Must the first argument
self
oftypes.MethodType
be a callable object? In other words, must the classFunction
be a callable type, i.e. mustFunction
have a method__call__
?If
self
is a callable object, does it take at least one argument?Does
types.MethodType(self, obj)
mean givingobj
as the first argument to the callable objectself
, i.e. curryingself
withobj
?How does
types.MethodType(self, obj)
create and return an instance oftypes.MethodType
?
Thanks.