This is perfectly normal.
The function myfunc
is replacecd by an instance of wrapper
. The signature of wrapper
is (*args)
. because it is a bound method, the first argument is the instance of MyClass
which is printed out after the string `Wrapper: '.
What's confusing you?
It's worth noting that if you use call
as a decorator from outside of MyClass
, it will generate a TypeError
. One way around this is to apply the staticmethod
decorator to it but then you can't call it during class construction.
It's a little bit hacky but I address how to have it both ways here.
update after comment
it gets the instance as the first argument regardless of if you type self
in the parameter list because after the class is created, and an instance instantiated, it is a bound method. when you call it in the form
@instance.call
def foo(bar):
return bar + 1
it expands to
def foo(bar):
return bar + 1
foo = instance.call(f)
but note that you are calling it on an instance! This will automatically expand to a call of the form
def foo(bar):
return bar + 1
foo = MyClass.call(instance, f)
This is how methods work. But you only defined call
to take one argument so this raises a TypeError
.
As for calling it during class construction, it works fine. but the function that it returns gets passed an instance of MyClass
when it is called for the same reason that I explained above. Specifically, whatever arguments you explicity pass to it come after the implicit and automatic placement of the instance that it is called upon at the front of the argument list.