]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-140790: pdb: Initialize instance variables in Pdb.__init__ (#140791)
authorM Bussonnier <bussonniermatthias@gmail.com>
Fri, 14 Nov 2025 03:18:54 +0000 (04:18 +0100)
committerGitHub <noreply@github.com>
Fri, 14 Nov 2025 03:18:54 +0000 (19:18 -0800)
Initialize lineno, stack, curindex, curframe, currentbp, and _user_requested_quit attributes in `Pdb.__init__``.

Lib/pdb.py
Misc/NEWS.d/next/Library/2025-10-30-12-36-19.gh-issue-140790._3T6-N.rst [new file with mode: 0644]

index fdc74198582eecdce5de784b998910add6add512..b799a113503502c13996352a3ef3617d6a7008ee 100644 (file)
@@ -398,6 +398,12 @@ class Pdb(bdb.Bdb, cmd.Cmd):
 
         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 @@ class Pdb(bdb.Bdb, cmd.Cmd):
         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 @@ class Pdb(bdb.Bdb, cmd.Cmd):
         """
         # 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 (file)
index 0000000..03856f0
--- /dev/null
@@ -0,0 +1 @@
+Initialize all Pdb's instance variables in ``__init__``,  remove some hasattr/getattr