hi i a class like this:
def Foo:
def calc(self):
print "calc"
def on_get(self):
print "on get"
def on_post(self):
print "on post"
I want to inject a pdb tracer in any method of the class that starts with on_
, so i thought of writing a decorator to do that.This is what i have until now.
def debuggable(cls):
from types import FunctionType
def pdb_injector(view):
def injector_wrapper():
import pdb; pdb.set_trace()
view()
return injector_wrapper
class wrapped(cls):
views = [x for x,y in cls.__dict__.items() if type(y) == FunctionType and 'on_' in x]
for view in views:
_view = getattr(cls,view)
_view = pdb_injector(_view)
setattr(cls ,view, _view)
return wrapped
When i do call Foo.on_get()
after adding @debuggable
to the Foo
class. i get this error:
TypeError: injector_wrapper() takes no arguments (1 given).
why am i getting this error?