Add set_trace to core debugger. #9947

Merged
merged 4 commits into from Sep 15, 2016

Projects

None yet

3 participants

@tillahoffmann
Contributor

This PR adds a set_trace method to IPython.core.debugger to mirror the functionality of IPython.terminal.debugger. See #9940 for a discussion.

@tillahoffmann tillahoffmann Add set_trace to core debugger.
ba43c3f
@takluyver takluyver commented on an outdated diff Sep 14, 2016
IPython/core/debugger.py
@@ -621,3 +621,14 @@ def do_where(self, arg):
self.print_stack_trace()
do_w = do_where
+
+
+def set_trace(frame=None, condition=True):
@takluyver
takluyver Sep 14, 2016 Member

Let's stick to the same API as pdb and IPython.terminal.debugger, with set_trace() taking no parameters. We can discuss adding parameters as a separate step, and if we do we'll want to keep core and terminal in sync.

@tillahoffmann tillahoffmann commented on an outdated diff Sep 14, 2016
IPython/core/debugger.py
@@ -621,3 +621,14 @@ def do_where(self, arg):
self.print_stack_trace()
do_w = do_where
+
+
+def set_trace(frame=None, condition=True):
+ """
+ Start debugging from `frame` if `condition` is satisfied.
+
+ If frame is not specified, debugging starts from caller's frame.
+ """
+ if condition:
+ pdb = Pdb()
@tillahoffmann
tillahoffmann Sep 14, 2016 edited Contributor

These shouldn't be tabs. Will fix in next commit.

@tillahoffmann tillahoffmann Remove condition from set_trace.
99b5ad4
@takluyver takluyver commented on the diff Sep 14, 2016
IPython/core/debugger.py
@@ -621,3 +621,13 @@ def do_where(self, arg):
self.print_stack_trace()
do_w = do_where
+
+
+def set_trace(frame=None):
@takluyver
takluyver Sep 14, 2016 Member

The other set_trace() functions also don't have a frame parameter, though the set_trace() method does. I'd either remove it from here, or also add it to the version in IPython.terminal. @Carreau, opinions?

Also, if we decide to keep the parameter, it should probably actually do something ;-)

@tillahoffmann
tillahoffmann Sep 14, 2016 Contributor

Yes, it should indeed do something. Let me know if you'd prefer to remove the frame parameter or add it to IPython.terminal as well.

@takluyver
takluyver Sep 14, 2016 Member

I could go either way, but I'd like to know what @Carreau thinks when he's online in a couple more hours. :-)

@Carreau
Carreau Sep 14, 2016 Member

Happy to add it to the function, it should likely be passed to Pdb.set_trace() by adding 1 to it, and we should even likely start the debugging 1 frame up from the current one to be consistent with normal Pdb.

@takluyver
takluyver Sep 14, 2016 Member

Makes sense, though it takes a frame object, not an offset number. Here's the set_trace definition from pdb:

def set_trace():
    Pdb().set_trace(sys._getframe().f_back)
tillahoffmann added some commits Sep 15, 2016
@tillahoffmann tillahoffmann Fix unused frame variable. 908750a
@tillahoffmann tillahoffmann Add frame parameter to terminal debugger.
9b36b69
@Carreau

Seem good to me ! (trying new GitHub reviews things)

@Carreau Carreau added this to the 5.2 milestone Sep 15, 2016
@Carreau
Member
Carreau commented Sep 15, 2016

Marking as 5.2 as it should be easy to backport.

@takluyver
Member

Looks good, thanks @tillahoffmann

@takluyver takluyver merged commit 185e47e into ipython:master Sep 15, 2016

3 checks passed

codecov/patch 60.00% of diff hit (target 0.00%)
Details
codecov/project 73.18% (+<.01%) compared to 41bc8e5
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@Carreau Carreau referenced this pull request Sep 18, 2016
Merged

Bunch of 5.x backport. #9959

@takluyver takluyver added a commit that referenced this pull request Jan 12, 2017
@takluyver @takluyver takluyver + takluyver Backport PR #9947: Add set_trace to core debugger.
This PR adds a `set_trace` method to `IPython.core.debugger` to mirror the functionality of `IPython.terminal.debugger`. See  9940 for a discussion.

Signed-off-by: Thomas Kluyver <thomas@kluyver.me.uk>
fd4a15c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment