Is there a way to step into decorated functions, skipping decorator code

I have a module which decorates some key functions with custom decorators.

Debugging these functions with pdb often is a bit of a pain, because every time I step into a decorated function I first have to step through the decorator code itself.

I could of course just set the debugger to break within the function I'm interested in, but as key functions they are called many times from many places so I usually prefer to start debugging outside the function.

I tried to illustrate it with code, but I don't know if that helps:

def i_dont_care_about_this(fn):
    def wrapper(*args, **kwargs):
        return fn(*args, **kwargs)
    return wrapper

def i_only_care_about_this():
    # no use to set pdb here

def i_am_here():
    import pdb; pdb.set_trace()

So, is there a way for me to step into i_only_care_about_this from i_am_herewithout going through i_dont_care_about_this?

Essentially I want to skip all decorator code when using s to (s)tep into a given decorated function.


If the decorator is purely for logging or other non-functional behavior, then make it a no-op for debugging - insert this code right after the definition of i_dont_care_about_this:

DEBUG = False
# uncomment this line when pdb'ing
# DEBUG = True
    i_dont_care_about_this = lambda fn : fn

But if it contains actual active code, then you will have to do the work using pdb methods, such as a conditionalized call to pdb.set_trace inside the code inside the decorator:

# (inside your function you want to debug)
    import pdb; pdb.set_trace()
# at your critical calling point

I don't think you can do that. It would change the meaning of step to be something very different.

However, there is a way to achieve something similar to what you want. Set a breakpoint in your decorated function and one just before the decorated function is called. Now, disable the breakpoint inside the function.

Now, when you run the code, it will only break when you reach the specific invocation you care about. Once that break happens, re-enable the breakpoint in the function and continue the execution. This will execute all the decorated code and break on the first line of the decorated function.

Need Your Help

version control/maintaining development local copies and working live copies and databases

database svn version-control control

This is a subject of common discussion, but through all my research I have not actually found a sound answer to this.

Need help storing additional registration info in register.aspx

c# .net

I am trying to create a custom profile to store additional registration info. With reference to another SO thread, I create a custom profile class, AccountProfile.cs, aside from the problem described

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.