https://github.com/python/cpython/commit/4885ecfbda4cc792691e5d488ef6cb09727eb417
commit: 4885ecfbda4cc792691e5d488ef6cb09727eb417
branch: main
author: M Bussonnier <[email protected]>
committer: gaogaotiantian <[email protected]>
date: 2025-11-13T19:18:54-08:00
summary:
gh-140790: pdb: Initialize instance variables in Pdb.__init__ (#140791)
Initialize lineno, stack, curindex, curframe, currentbp, and
_user_requested_quit attributes in `Pdb.__init__``.
files:
A Misc/NEWS.d/next/Library/2025-10-30-12-36-19.gh-issue-140790._3T6-N.rst
M Lib/pdb.py
diff --git a/Lib/pdb.py b/Lib/pdb.py
index fdc74198582eec..b799a113503502 100644
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -398,6 +398,12 @@ def __init__(self, completekey='tab', stdin=None,
stdout=None, skip=None,
self._current_task = None
+ self.lineno = None
+ self.stack = []
+ self.curindex = 0
+ self.curframe = None
+ self._user_requested_quit = False
+
def set_trace(self, frame=None, *, commands=None):
Pdb._last_pdb_instance = self
if frame is None:
@@ -474,7 +480,7 @@ def forget(self):
self.lineno = None
self.stack = []
self.curindex = 0
- if hasattr(self, 'curframe') and self.curframe:
+ if self.curframe:
self.curframe.f_globals.pop('__pdb_convenience_variables', None)
self.curframe = None
self.tb_lineno.clear()
@@ -1493,7 +1499,7 @@ def checkline(self, filename, lineno,
module_globals=None):
"""
# this method should be callable before starting debugging, so default
# to "no globals" if there is no current frame
- frame = getattr(self, 'curframe', None)
+ frame = self.curframe
if module_globals is None:
module_globals = frame.f_globals if frame else None
line = linecache.getline(filename, lineno, module_globals)
diff --git
a/Misc/NEWS.d/next/Library/2025-10-30-12-36-19.gh-issue-140790._3T6-N.rst
b/Misc/NEWS.d/next/Library/2025-10-30-12-36-19.gh-issue-140790._3T6-N.rst
new file mode 100644
index 00000000000000..03856f0b9b6d0a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-10-30-12-36-19.gh-issue-140790._3T6-N.rst
@@ -0,0 +1 @@
+Initialize all Pdb's instance variables in ``__init__``, remove some
hasattr/getattr
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]