Skip to content

Commit 5d677c5

Browse files
GH-101673: Fix pdb bug where local variable changes are lost after longlist (#101674)
1 parent f6ca71a commit 5d677c5

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

Lib/pdb.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,6 @@ def find_function(funcname, filename):
107107
return funcname, filename, lineno
108108
return None
109109

110-
def getsourcelines(obj):
111-
lines, lineno = inspect.findsource(obj)
112-
if inspect.isframe(obj) and obj.f_globals is obj.f_locals:
113-
# must be a module frame: do not try to cut a block out of it
114-
return lines, 1
115-
elif inspect.ismodule(obj):
116-
return lines, 1
117-
return inspect.getblock(lines[lineno:]), lineno+1
118-
119110
def lasti2lineno(code, lasti):
120111
linestarts = list(dis.findlinestarts(code))
121112
linestarts.reverse()
@@ -1357,7 +1348,7 @@ def do_longlist(self, arg):
13571348
filename = self.curframe.f_code.co_filename
13581349
breaklist = self.get_file_breaks(filename)
13591350
try:
1360-
lines, lineno = getsourcelines(self.curframe)
1351+
lines, lineno = inspect.getsourcelines(self.curframe)
13611352
except OSError as err:
13621353
self.error(err)
13631354
return
@@ -1373,7 +1364,7 @@ def do_source(self, arg):
13731364
except:
13741365
return
13751366
try:
1376-
lines, lineno = getsourcelines(obj)
1367+
lines, lineno = inspect.getsourcelines(obj)
13771368
except (OSError, TypeError) as err:
13781369
self.error(err)
13791370
return

Lib/test/test_pdb.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,35 @@ def test_pdb_issue_gh_94215():
14741474
(Pdb) continue
14751475
"""
14761476

1477+
def test_pdb_issue_gh_101673():
1478+
"""See GH-101673
1479+
1480+
Make sure ll won't revert local variable assignment
1481+
1482+
>>> def test_function():
1483+
... a = 1
1484+
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
1485+
1486+
>>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
1487+
... '!a = 2',
1488+
... 'll',
1489+
... 'p a',
1490+
... 'continue'
1491+
... ]):
1492+
... test_function()
1493+
--Return--
1494+
> <doctest test.test_pdb.test_pdb_issue_gh_101673[0]>(3)test_function()->None
1495+
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
1496+
(Pdb) !a = 2
1497+
(Pdb) ll
1498+
1 def test_function():
1499+
2 a = 1
1500+
3 -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
1501+
(Pdb) p a
1502+
2
1503+
(Pdb) continue
1504+
"""
1505+
14771506

14781507
@support.requires_subprocess()
14791508
class PdbTestCase(unittest.TestCase):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a :mod:`pdb` bug where ``ll`` clears the changes to local variables.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy