Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
It injects Pdb into the globals of pdb.set_trace, to use the given frame.
"""
if frame is None:
frame = sys._getframe().f_back
if cleanup:
pdbpp.cleanup()
class PdbForFrame(Pdb):
def set_trace(self, _frame, *args, **kwargs):
super(PdbForFrame, self).set_trace(frame, *args, **kwargs)
newglobals = pdbpp.set_trace.__globals__.copy()
newglobals['Pdb'] = PdbForFrame
new_set_trace = pdbpp.rebind_globals(pdbpp.set_trace, newglobals)
new_set_trace(**kwds)
def set_trace_via_module(frame=None, cleanup=True, Pdb=PdbTest, **kwds):
"""set_trace helper that goes through pdb.set_trace.
It injects Pdb into the globals of pdb.set_trace, to use the given frame.
"""
if frame is None:
frame = sys._getframe().f_back
if cleanup:
pdbpp.cleanup()
class PdbForFrame(Pdb):
def set_trace(self, _frame, *args, **kwargs):
super(PdbForFrame, self).set_trace(frame, *args, **kwargs)
newglobals = pdbpp.set_trace.__globals__.copy()
newglobals['Pdb'] = PdbForFrame
new_set_trace = pdbpp.rebind_globals(pdbpp.set_trace, newglobals)
new_set_trace(**kwds)