I am trying to apply the timing decorator described here to a method within a class instead of a standalone method. How should this be done?
I am getting this error:
TypeError: unbound method wrapper() must be called with SomeClass instance as first argument (got float instance instead)
EDIT
Thanks to your comment, I think I know what the problem is. This doesn’t work:
for exactly the reason you said.
TypeError: unbound method wrapper() must be called with A instance as first argument (got int instance instead)
But this does:
So the order matters. I think what’s going on here is that it’s fooling the way python handles bound methods: When python looks at the member a, it has to make a decision:
If it gets a regular function, it will do (1), and @timings produces a regular function.
Does this solve the problem?