This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: enhance pdb.set_trace() to run when the specified condition is true
Type: enhancement Stage: resolved
Components: Versions: Python 3.9
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: alex-ulnv, jaraco, lisroach, zach.ware
Priority: normal Keywords: patch

Created on 2019-09-08 10:44 by alex-ulnv, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 15731 closed alex-ulnv, 2019-09-08 11:31
Messages (6)
msg351324 - (view) Author: Alexander Ulyanov (alex-ulnv) * Date: 2019-09-08 10:44
Through out my experience with python debugger, I often found myself creating if-statements around set_trace() instructions. This patch introduces a key-word argument that allows to pass in a boolean or a condition that evaluates to boolean to control whether pdb.set_trace() command needs to be executed.
msg351448 - (view) Author: Lisa Roach (lisroach) * (Python committer) Date: 2019-09-09 12:59
Does this flag make things much easier? You would still need an if statement in order to correctly pass in True/False for the trigger flag.
msg351643 - (view) Author: Alexander Ulyanov (alex-ulnv) * Date: 2019-09-10 13:09
Perhaps it's a matter of preference. I found it convenient, since passing in a boolean expression allows me to get rid of extra if-blocks thus reducing lines of code and increasing debugging speed. I wanted to share my idea with the community - but please feel free to close the issue if you find it trivial.

############## SAMPLE USE CASE ##############
import pdb

def square(i):
	pdb.set_trace(trigger=not isinstance(i, (float, int)))
	print(i**2)

# debug: hunting for TypeError
a = 2
square(a) # will not execute set_trace()
b = None
square(b) # will execute set_trace()
msg351797 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2019-09-11 10:29
You could just do

breakpoint() if trigger else None

Concise, easy, and avoids complicating set_trace().
msg351800 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2019-09-11 10:31
Or even more concise:

trigger and breakpoint()
msg351868 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2019-09-11 13:33
I was actually leaning in favor of this, but Jason's examples are very compelling and require no changes to other `breakpoint()`-compatible debuggers to work as expected.

Thanks for the idea, though!
History
Date User Action Args
2022-04-11 14:59:19adminsetgithub: 82235
2019-09-11 13:33:09zach.waresetstatus: open -> closed

nosy: + zach.ware
messages: + msg351868

resolution: rejected
stage: patch review -> resolved
2019-09-11 10:31:05jaracosetmessages: + msg351800
2019-09-11 10:29:10jaracosetnosy: + jaraco
messages: + msg351797
2019-09-10 13:09:54alex-ulnvsetmessages: + msg351643
2019-09-09 12:59:03lisroachsetnosy: + lisroach
messages: + msg351448
2019-09-08 12:52:00alex-ulnvsettype: enhancement
2019-09-08 11:31:01alex-ulnvsetkeywords: + patch
stage: patch review
pull_requests: + pull_request15384
2019-09-08 10:44:15alex-ulnvcreate