Skip to content

Commit 4885ecf

Browse files
authored
pythongh-140790: pdb: Initialize instance variables in Pdb.__init__ (python#140791)
Initialize lineno, stack, curindex, curframe, currentbp, and _user_requested_quit attributes in `Pdb.__init__``.
1 parent a486d45 commit 4885ecf

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Lib/pdb.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,12 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
398398

399399
self._current_task = None
400400

401+
self.lineno = None
402+
self.stack = []
403+
self.curindex = 0
404+
self.curframe = None
405+
self._user_requested_quit = False
406+
401407
def set_trace(self, frame=None, *, commands=None):
402408
Pdb._last_pdb_instance = self
403409
if frame is None:
@@ -474,7 +480,7 @@ def forget(self):
474480
self.lineno = None
475481
self.stack = []
476482
self.curindex = 0
477-
if hasattr(self, 'curframe') and self.curframe:
483+
if self.curframe:
478484
self.curframe.f_globals.pop('__pdb_convenience_variables', None)
479485
self.curframe = None
480486
self.tb_lineno.clear()
@@ -1493,7 +1499,7 @@ def checkline(self, filename, lineno, module_globals=None):
14931499
"""
14941500
# this method should be callable before starting debugging, so default
14951501
# to "no globals" if there is no current frame
1496-
frame = getattr(self, 'curframe', None)
1502+
frame = self.curframe
14971503
if module_globals is None:
14981504
module_globals = frame.f_globals if frame else None
14991505
line = linecache.getline(filename, lineno, module_globals)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Initialize all Pdb's instance variables in ``__init__``, remove some hasattr/getattr

0 commit comments

Comments
 (0)