Skip to content

Avoid more exception raising hacks (old Python 2 code) #2462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions Pythonwin/pywin/debugger/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,14 +818,12 @@ def _dump_frame_(self, frame, name=None):
print(repr(name), "None")

def set_trace(self):
# Start debugging from _2_ levels up!
try:
1 + ""
except:
frame = sys.exc_info()[2].tb_frame.f_back.f_back
frames = traceback.walk_stack(sys._getframe())
# Start debugging from _1_ level up!
next(frames)
self.reset()
self.userbotframe = None
while frame:
for frame, i in frames:
# scriptutils.py creates a local variable with name
# '_debugger_stop_frame_', and we don't go past it
# (everything above this is Pythonwin framework code)
Expand All @@ -835,7 +833,6 @@ def set_trace(self):

frame.f_trace = self.trace_dispatch
self.botframe = frame
frame = frame.f_back
self.set_step()
sys.settrace(self.trace_dispatch)

Expand Down
7 changes: 2 additions & 5 deletions com/win32comext/axdebug/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,8 @@ def __init__(self, interfaceMaker=None, processName=None):
self.pydebugger.AttachApp(self.app, contProvider)

def Break(self):
# Get the frame we start debugging from - this is the frame 1 level up
try:
1 + ""
except:
frame = sys.exc_info()[2].tb_frame.f_back
# Get the frame we start debugging from
frame = traceback.tb_frame if (traceback := sys.exc_info()[2]) else None

# Get/create the debugger, and tell it to break.
self.app.StartDebugSession()
Expand Down
6 changes: 3 additions & 3 deletions com/win32comext/axdebug/stackframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Provides Implements a nearly complete wrapper for a stack frame.
"""

import traceback

import pythoncom

from . import axdebug, expressions, gateways
Expand All @@ -19,9 +21,8 @@ class EnumDebugStackFrames(gateways.EnumDebugStackFrames):

def __init__(self, debugger):
infos = []
frame = debugger.currentframe
# print("Stack check")
while frame:
for frame, i in traceback.walk_stack(debugger.currentframe):
# print(" Checking frame", frame.f_code.co_filename, frame.f_lineno-1, frame.f_trace)
# Get a DebugCodeContext for the stack frame. If we fail, then it
# is not debuggable, and therefore not worth displaying.
Expand All @@ -44,7 +45,6 @@ def __init__(self, debugger):
# print("- Kept!")
# else:
# print("- rejected")
frame = frame.f_back

gateways.EnumDebugStackFrames.__init__(self, infos, 0)

Expand Down