Skip to content

Commit d4f8faf

Browse files
[3.10] GH-101673: Fix pdb bug where local variable changes are lost after longlist (#101674) (#102633)
GH-101673: Fix pdb bug where local variable changes are lost after longlist (#101674) (cherry picked from commit 5d677c5) Co-authored-by: gaogaotiantian <gaogaotiantian@hotmail.com>
1 parent 5e10479 commit d4f8faf

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
@@ -104,15 +104,6 @@ def find_function(funcname, filename):
104104
return funcname, filename, lineno
105105
return None
106106

107-
def getsourcelines(obj):
108-
lines, lineno = inspect.findsource(obj)
109-
if inspect.isframe(obj) and obj.f_globals is obj.f_locals:
110-
# must be a module frame: do not try to cut a block out of it
111-
return lines, 1
112-
elif inspect.ismodule(obj):
113-
return lines, 1
114-
return inspect.getblock(lines[lineno:]), lineno+1
115-
116107
def lasti2lineno(code, lasti):
117108
linestarts = list(dis.findlinestarts(code))
118109
linestarts.reverse()
@@ -1273,7 +1264,7 @@ def do_longlist(self, arg):
12731264
filename = self.curframe.f_code.co_filename
12741265
breaklist = self.get_file_breaks(filename)
12751266
try:
1276-
lines, lineno = getsourcelines(self.curframe)
1267+
lines, lineno = inspect.getsourcelines(self.curframe)
12771268
except OSError as err:
12781269
self.error(err)
12791270
return
@@ -1289,7 +1280,7 @@ def do_source(self, arg):
12891280
except:
12901281
return
12911282
try:
1292-
lines, lineno = getsourcelines(obj)
1283+
lines, lineno = inspect.getsourcelines(obj)
12931284
except (OSError, TypeError) as err:
12941285
self.error(err)
12951286
return

Lib/test/test_pdb.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,35 @@ def test_pdb_issue_43318():
13511351
4
13521352
"""
13531353

1354+
def test_pdb_issue_gh_101673():
1355+
"""See GH-101673
1356+
1357+
Make sure ll won't revert local variable assignment
1358+
1359+
>>> def test_function():
1360+
... a = 1
1361+
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
1362+
1363+
>>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
1364+
... '!a = 2',
1365+
... 'll',
1366+
... 'p a',
1367+
... 'continue'
1368+
... ]):
1369+
... test_function()
1370+
--Return--
1371+
> <doctest test.test_pdb.test_pdb_issue_gh_101673[0]>(3)test_function()->None
1372+
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
1373+
(Pdb) !a = 2
1374+
(Pdb) ll
1375+
1 def test_function():
1376+
2 a = 1
1377+
3 -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
1378+
(Pdb) p a
1379+
2
1380+
(Pdb) continue
1381+
"""
1382+
13541383

13551384
class PdbTestCase(unittest.TestCase):
13561385
def tearDown(self):
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