Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixed zero lineno issue for pdb
Co-authored-by: Artem Mukhin <ortem00@gmail.com>
  • Loading branch information
gaogaotiantian and artemmukhin committed Apr 5, 2023
commit 0b3c3b8eac6da570a4ecb91c5abe2aa83c9150e6
6 changes: 6 additions & 0 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,9 @@ def do_longlist(self, arg):
breaklist = self.get_file_breaks(filename)
try:
lines, lineno = inspect.getsourcelines(self.curframe)
# inspect.getsourcelines() returns lineno = 0 for
# module-level frame which breaks our code print line number
lineno = max(1, lineno)
Comment thread
gaogaotiantian marked this conversation as resolved.
Outdated
except OSError as err:
self.error(err)
return
Expand All @@ -1368,6 +1371,9 @@ def do_source(self, arg):
return
try:
lines, lineno = inspect.getsourcelines(obj)
# inspect.getsourcelines() returns lineno = 0 for
# module-level frame which breaks our code print line number
lineno = max(1, lineno)
Comment thread
gaogaotiantian marked this conversation as resolved.
Outdated
except (OSError, TypeError) as err:
self.error(err)
return
Expand Down
25 changes: 25 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,31 @@ def test_pdb_issue_gh_101673():
(Pdb) continue
"""

def test_pdb_issue_gh_103225():
"""See GH-103225

Make sure longlist uses 1-based line numbers in frames that correspond to a module

>>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
... 'longlist',
... 'continue'
... ]):
... a = 1
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
... b = 2
> <doctest test.test_pdb.test_pdb_issue_gh_103225[0]>(7)<module>()
-> b = 2
(Pdb) longlist
1 with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
2 'longlist',
3 'continue'
4 ]):
5 a = 1
6 import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
7 -> b = 2
(Pdb) continue
"""


@support.requires_subprocess()
class PdbTestCase(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed the line number display bug on modules for :mod:`pdb`
Comment thread
gaogaotiantian marked this conversation as resolved.
Outdated