Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

pdb loses local variable change after command longlist #101673

Closed
Labels
type-bugAn unexpected behavior, bug, or error
@gaogaotiantian

Description

@gaogaotiantian

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:

  1. ./python -m test -j3 passed
  2. The original bug is fixed
  3. ll still 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

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp