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.MethodTypeThe 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
selfoftypes.MethodTypebe a callable object? In other words, must the classFunctionbe a callable type, i.e. mustFunctionhave a method__call__?If
selfis a callable object, does it take at least one argument?Does
types.MethodType(self, obj)mean givingobjas the first argument to the callable objectself, i.e. curryingselfwithobj?How does
types.MethodType(self, obj)create and return an instance oftypes.MethodType?
Thanks.