classification
Title: local variable changes lost after pdb jump command
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: iritkatriel, scotchka, xdegaye
Priority: normal Keywords: patch

Created on 2014-10-08 10:21 by xdegaye, last changed 2020-10-19 22:28 by iritkatriel. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11041 closed python-dev, 2018-12-09 03:46
Messages (3)
msg228783 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2014-10-08 10:21
With the following pdb_jump.py script:

def foo(x):
    import pdb; pdb.set_trace()
    lineno = 3
    lineno = 4

foo(1)


The change made to 'x' is lost after a jump to line 4:

$ ./python ~/tmp/test/pdb_jump.py
> ~/tmp/test/pdb_jump.py(3)foo()
-> lineno = 3
(Pdb) x = 123
(Pdb) jump 4
> ~/tmp/test/pdb_jump.py(4)foo()
-> lineno = 4
(Pdb) x
1
(Pdb)


The problem is that the Bdb format_stack_entry() method refers to frame.f_locals and thus overwrites the changes made to the f_locals dictionary as the f_locals dictionary is updated from the actual frame locals whenever the f_locals accessor is called as stated in a comment of the Pdb setup() method.
msg343309 - (view) Author: Henry Chen (scotchka) * Date: 2019-05-23 16:37
PEP 558 will fix this issue, which I've verified with the proposed implementation (https://github.com/python/cpython/pull/3640/files).

Perhaps this issue can be closed?
msg376025 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-08-28 09:11
This is now resolved, on Python 3.10 I get:

>python -m pdb tmp1.py
Running Release|Win32 interpreter...
> c:\users\user\src\cpython\tmp1.py(1)<module>()
-> def foo(x):
(Pdb) jump 4
> c:\users\user\src\cpython\tmp1.py(4)<module>()
-> lineno = 4
(Pdb) q

C:\Users\User\src\cpython>python -m pdb tmp1.py
Running Release|Win32 interpreter...
> c:\users\user\src\cpython\tmp1.py(1)<module>()
-> def foo(x):
(Pdb) x=123
(Pdb) jump 4
> c:\users\user\src\cpython\tmp1.py(4)<module>()
-> lineno = 4
(Pdb) x
123
(Pdb)


I believe this ticket can be closed.
History
Date User Action Args
2020-10-19 22:28:44iritkatrielsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-09-19 19:01:49georg.brandlsetnosy: - georg.brandl
2020-08-28 09:11:28iritkatrielsetnosy: + iritkatriel
messages: + msg376025
2019-05-23 16:37:29scotchkasetmessages: + msg343309
2018-12-09 19:15:08scotchkasetnosy: + scotchka
2018-12-09 03:46:02python-devsetkeywords: + patch
stage: patch review
pull_requests: + pull_request10278
2014-10-08 10:21:49xdegayecreate