Consider the following code:
import functools
import inspect
class Foo:
def foo_fn(self, hello, world):
print(hello, world)
class FooWrapper:
def __init__(self, foo_class):
self._foo = foo_class()
for key, value in inspect.getmembers(self._foo):
if inspect.ismethod(value):
bound_fn = functools.partial(self.foo_wrapper_fn, self, value)
setattr(self._foo, key, bound_fn)
def foo_wrapper_fn(self_wrapper, self_foo, bound_method, hello, world):
bound_method(hello, world)
def make_foo(Foo):
wrapper = FooWrapper(Foo)
return wrapper._foo
a = make_foo(Foo)
a.foo_fn("hello", "world")
How does this ordering of the function
foo_wrapper_fn()
parameters like(self_wrapper, self_foo, bound_method, hello, world)
come to be? and not like so:self_wrapper, bound_fn, self_foo, hello, world
, sinceself_wrapper
andbound_fn
were partially bound first?Is it ok for the return of
functool.partial
(and notfunctool.partialmethod
) to be called by an object (a.foo_fn
)?If I replace it with
functools.partialmethod(self.foo_wrapper_fn, self, value)
why does this error come up?TypeError: 'partialmethod' object is not callable