diff options
Diffstat (limited to 'Lib/pdb.py')
| -rwxr-xr-x | Lib/pdb.py | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -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: |
