Skip to content

Commit 91a693a

Browse files
Fixed zero lineno issue for pdb
1 parent a62ff97 commit 91a693a

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Lib/pdb.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,9 @@ def do_longlist(self, arg):
13521352
breaklist = self.get_file_breaks(filename)
13531353
try:
13541354
lines, lineno = inspect.getsourcelines(self.curframe)
1355+
# inspect.getsourcelines() returns 0 for module-level frame
1356+
# and it does not make sense for the code display
1357+
lineno = max(1, lineno)
13551358
except OSError as err:
13561359
self.error(err)
13571360
return
@@ -1368,6 +1371,9 @@ def do_source(self, arg):
13681371
return
13691372
try:
13701373
lines, lineno = inspect.getsourcelines(obj)
1374+
# inspect.getsourcelines() returns 0 for module-level frame
1375+
# and it does not make sense for the code display
1376+
lineno = max(1, lineno)
13711377
except (OSError, TypeError) as err:
13721378
self.error(err)
13731379
return

Lib/test/test_pdb.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,31 @@ def test_pdb_issue_gh_101673():
16751675
(Pdb) continue
16761676
"""
16771677

1678+
def test_pdb_issue_gh_103225():
1679+
"""See GH-103225
1680+
1681+
Make sure longlist uses 1-based line numbers in frames that correspond to a module
1682+
1683+
>>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
1684+
... 'longlist',
1685+
... 'continue'
1686+
... ]):
1687+
... a = 1
1688+
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
1689+
... b = 2
1690+
> <doctest test.test_pdb.test_pdb_issue_gh_103225[0]>(7)<module>()
1691+
-> b = 2
1692+
(Pdb) longlist
1693+
1 with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
1694+
2 'longlist',
1695+
3 'continue'
1696+
4 ]):
1697+
5 a = 1
1698+
6 import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
1699+
7 -> b = 2
1700+
(Pdb) continue
1701+
"""
1702+
16781703

16791704
@support.requires_subprocess()
16801705
class PdbTestCase(unittest.TestCase):

0 commit comments

Comments
 (0)