how can i use python decorator to specify a class that allows you to define which methods should be debugged?

You could build a subclass, and decorate methods of the subclass. That way you do not modify the original class which can be expected from a decorator:

def cdebug(cls):
    class wrapper(cls):
    for name, method in inspect.getmembers(cls, inspect.isfunction):
        # this one will not decorate special methods
        if not (name.startswith('__') and name.endswith('__')):
            setattr(wrapper,name, _debug(getattr(cls, name)))
    return wrapper

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top