summaryrefslogtreecommitdiffstats
path: root/Lib/pdb.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/pdb.py')
-rwxr-xr-xLib/pdb.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/pdb.py b/Lib/pdb.py
index f9c5bee..d3824e1 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -1348,7 +1348,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
filename = self.curframe.f_code.co_filename
breaklist = self.get_file_breaks(filename)
try:
- lines, lineno = inspect.getsourcelines(self.curframe)
+ lines, lineno = self._getsourcelines(self.curframe)
except OSError as err:
self.error(err)
return
@@ -1364,7 +1364,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
except:
return
try:
- lines, lineno = inspect.getsourcelines(obj)
+ lines, lineno = self._getsourcelines(obj)
except (OSError, TypeError) as err:
self.error(err)
return
@@ -1643,6 +1643,16 @@ class Pdb(bdb.Bdb, cmd.Cmd):
self.run(target.code)
+ def _getsourcelines(self, obj):
+ # GH-103319
+ # inspect.getsourcelines() returns lineno = 0 for
+ # module-level frame which breaks our code print line number
+ # This method should be replaced by inspect.getsourcelines(obj)
+ # once this bug is fixed in inspect
+ lines, lineno = inspect.getsourcelines(obj)
+ lineno = max(1, lineno)
+ return lines, lineno
+
# Collect all command help into docstring, if not run with -OO
if __doc__ is not None: