Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Description
Bug report
In pdb,ll will clear the local variable change.
defmain():a=1breakpoint()print(a)main()
->print(a)(Pdb)pa1(Pdb) !a=2(Pdb)pa2(Pdb)ll1defmain():2a=13breakpoint()4->print(a)(Pdb)pa1(Pdb)s1--Return--
As you can tell,a was changed through!a = 2 but it was reverted afterll.print(a) also prints the unmodified value. Withoutll, everything works fine.
The reason lies ingetsourcelines inpdb.py. In that function, it tried to accessobj.f_locals, which will refresh the dict withPyFrame_FastToLocalsWithError as it's a property now.
ifinspect.isframe(obj)andobj.f_globalsisobj.f_locals:
As a result, the local variable changes will be erased.
The original reason to check ifobj.f_globals is obj.f_locals is to check whetherobj is an module frame. Now that it has side effects to pdb, we can do the check with:
ifinspect.isframe(obj)andobj.f_code.co_name=="<module>":
It might not be the most delicate way, but I can't think of a situation where this won't work.
I did this change locally and I have confirmed:
./python -m test -j3passed- The original bug is fixed
llstill prints the full file for module frame
I'll make a PR soon and please let me know if there are any concerns about the fix.
Your environment
- CPython versions tested on: 3.11.1
- Operating system and architecture: Ubuntu 20.04