mirror of
https://github.com/python/cpython.git
synced 2025-10-02 05:12:23 +00:00
GH-101673: Fix pdb bug where local variable changes are lost after longlist (GH-101674)
(cherry picked from commit 5d677c556f
)
Co-authored-by: gaogaotiantian <gaogaotiantian@hotmail.com>
This commit is contained in:
parent
6829b1256a
commit
78560261a2
3 changed files with 32 additions and 11 deletions
13
Lib/pdb.py
13
Lib/pdb.py
|
@ -107,15 +107,6 @@ def find_function(funcname, filename):
|
||||||
return funcname, filename, lineno
|
return funcname, filename, lineno
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def getsourcelines(obj):
|
|
||||||
lines, lineno = inspect.findsource(obj)
|
|
||||||
if inspect.isframe(obj) and obj.f_globals is obj.f_locals:
|
|
||||||
# must be a module frame: do not try to cut a block out of it
|
|
||||||
return lines, 1
|
|
||||||
elif inspect.ismodule(obj):
|
|
||||||
return lines, 1
|
|
||||||
return inspect.getblock(lines[lineno:]), lineno+1
|
|
||||||
|
|
||||||
def lasti2lineno(code, lasti):
|
def lasti2lineno(code, lasti):
|
||||||
linestarts = list(dis.findlinestarts(code))
|
linestarts = list(dis.findlinestarts(code))
|
||||||
linestarts.reverse()
|
linestarts.reverse()
|
||||||
|
@ -1357,7 +1348,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
filename = self.curframe.f_code.co_filename
|
filename = self.curframe.f_code.co_filename
|
||||||
breaklist = self.get_file_breaks(filename)
|
breaklist = self.get_file_breaks(filename)
|
||||||
try:
|
try:
|
||||||
lines, lineno = getsourcelines(self.curframe)
|
lines, lineno = inspect.getsourcelines(self.curframe)
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
self.error(err)
|
self.error(err)
|
||||||
return
|
return
|
||||||
|
@ -1373,7 +1364,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
lines, lineno = getsourcelines(obj)
|
lines, lineno = inspect.getsourcelines(obj)
|
||||||
except (OSError, TypeError) as err:
|
except (OSError, TypeError) as err:
|
||||||
self.error(err)
|
self.error(err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -1474,6 +1474,35 @@ def test_pdb_issue_gh_94215():
|
||||||
(Pdb) continue
|
(Pdb) continue
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def test_pdb_issue_gh_101673():
|
||||||
|
"""See GH-101673
|
||||||
|
|
||||||
|
Make sure ll won't revert local variable assignment
|
||||||
|
|
||||||
|
>>> def test_function():
|
||||||
|
... a = 1
|
||||||
|
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
|
||||||
|
|
||||||
|
>>> with PdbTestInput([ # doctest: +NORMALIZE_WHITESPACE
|
||||||
|
... '!a = 2',
|
||||||
|
... 'll',
|
||||||
|
... 'p a',
|
||||||
|
... 'continue'
|
||||||
|
... ]):
|
||||||
|
... test_function()
|
||||||
|
--Return--
|
||||||
|
> <doctest test.test_pdb.test_pdb_issue_gh_101673[0]>(3)test_function()->None
|
||||||
|
-> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
|
||||||
|
(Pdb) !a = 2
|
||||||
|
(Pdb) ll
|
||||||
|
1 def test_function():
|
||||||
|
2 a = 1
|
||||||
|
3 -> import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
|
||||||
|
(Pdb) p a
|
||||||
|
2
|
||||||
|
(Pdb) continue
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
@support.requires_subprocess()
|
@support.requires_subprocess()
|
||||||
class PdbTestCase(unittest.TestCase):
|
class PdbTestCase(unittest.TestCase):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix a :mod:`pdb` bug where ``ll`` clears the changes to local variables.
|
Loading…
Add table
Add a link
Reference in a new issue