GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — it's no longer possible to delete items from f_locals (FrameLocalsProxy) in 3.13+ · Issue #125590 · python/cpython

it's no longer possible to delete items from f_locals (FrameLocalsProxy) in 3.13+ #125590

New issue
Copy link
New issue
Copy link
Closed
Closed
it's no longer possible to delete items from f_locals (FrameLocalsProxy) in 3.13+#125590
Copy link
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@113908
113908
opened on Oct 16, 2024
Issue body actions

Bug report

Bug description:

           try:
                driver.switch_to.alert.accept()
                driver.switch_to.alert.dismiss()
            except:
                pass

In the example script above, if the code falls into the except: pass block due to an alert not being displayed, the script will ultimately fail (even if no coding errors are encountered) with FAILED (errors=1) .
Also, the following messages will be displayed in the output:
image

This code works fine in Python 3.12. The script succeeds with message OK and none of the above error messages. We can't move to 3.13 version until this is fixed.

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Linked PRs

  • gh-125590: Allow FrameLocalsProxy to delete and pop keys from extra locals #125616
  • [3.13] gh-125590: Allow FrameLocalsProxy to delete and pop keys from extra locals (GH-125616) #125797

Activity

  1. 113908
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Oct 16, 2024
  2. JelleZijlstra commented on Oct 16, 2024

    @JelleZijlstra
    JelleZijlstra
    on Oct 16, 2024
    Member
    More actions

    This sounds like an issue in the version of pydevd bundled by the Microsoft Python extension.

    I assume it's related to the FrameLocalsProxy changes from PEP-667; cc @gaogaotiantian.

  3. ZeroIntensity commented on Oct 16, 2024

    @ZeroIntensity
    ZeroIntensity
    on Oct 16, 2024
    Member
    More actions

    Maybe FrameLocalsProxy should just implement pop? (Or better yet, the rest of the dict interface.)

  4. ZeroIntensity
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    3.13only security fixesonly security fixes
    3.14bugs and security fixesbugs and security fixes
    on Oct 16, 2024
  5. graingert commented on Oct 16, 2024

    @graingert
    graingert
    on Oct 16, 2024
    Contributor
    More actions

    Maybe FrameLocalsProxy should just implement pop? (Or better yet, the rest of the dict interface.)

    problem is you cannot remove items from FrameLocalsProxy:

    cpython/Objects/frameobject.c

    Line 162 in d83fcf8

    PyErr_SetString(PyExc_TypeError, "cannot remove variables from FrameLocalsProxy");

    I think pydevd has to do

    try:
        del frame.f_locals["__exception__"]
    except KeyError:
        pass
    except TypeError:
        frame.f_locals["__exception__"] = None
    Reacted by Jelle Zijlstra
  6. gaogaotiantian commented on Oct 16, 2024

    @gaogaotiantian
    gaogaotiantian
    on Oct 16, 2024
    Member
    More actions

    The reason why FrameLocalsProxy did not support pop and del in the first place, is because it does not make sense to "remove" a local variable from the frame. However, in this specific case, the debugger is trying to remove an extra variable, which is artificially added. I think it might be fine to check if it's an actual local variable and only report error when it is.

    @markshannon and @gvanrossum as this was the discussion result from PEP 667 implementation.

    Reacted by Peter Bierma
  7. ZeroIntensity commented on Oct 16, 2024

    @ZeroIntensity
    ZeroIntensity
    on Oct 16, 2024
    Member
    More actions

    I'm not particularly familiar with how PEP 667 was implemented. From my understanding, deleting from f_locals was previously possible--is it that it can't be implemented right now, or is it that it's dangerous to expose to users?

  8. markshannon commented on Oct 16, 2024

    @markshannon
    markshannon
    on Oct 16, 2024
    Member
    More actions

    Popping and deleting keys in the "extras" dict should be fine.
    It gets complicated when the key is a "fast" local.

    In the style of the PEP, this would give us:

        def __delitem__(self, name):
            del self._extra_locals[name]
    
        def pop(self, name, default):
            return self._extra_locals.pop(name, default)
    Reacted by Guido van Rossum
  9. gaogaotiantian commented on Oct 16, 2024

    @gaogaotiantian
    gaogaotiantian
    on Oct 16, 2024
    Member
    More actions

    The semantics of f_locals has changed. f_locals used to be a pure dict which was written back to the real locals on certain occasions (the most common one is returning from trace functions). The old behavior, when you remove a key from f_locals, if it was written back, was to set the local variable to None and generate a warning - a very inconsistent and confusing behavior.

  10. gaogaotiantian commented on Oct 16, 2024

    @gaogaotiantian
    gaogaotiantian
    on Oct 16, 2024
    Member
    More actions

    Popping and deleting keys in the "extras" dict should be fine. It gets complicated when the key is a "fast" local.

    Let's allow popping and deleting keys in extras, and generate an exception (we are generating one now on del) if the user tries to remove a real local variable. Do we consider this a bug so we need to backport it to 3.13?

    Reacted by Guido van Rossum
  11. graingert
    changed the title [-]try except pass results in a script failure and system errors when code falls into pass logic - new bug in Python 3.13[/-] [+]it's no longer possible to delete items from f_locals (FrameLocalProxy) in 3.13+[/+] on Oct 16, 2024
  12. graingert
    changed the title [-]it's no longer possible to delete items from f_locals (FrameLocalProxy) in 3.13+[/-] [+]it's no longer possible to delete items from f_locals (FrameLocalsProxy) in 3.13+[/+] on Oct 16, 2024
  13. graingert commented on Oct 16, 2024

    @graingert
    graingert
    on Oct 16, 2024
    Contributor
    More actions

    The semantics of f_locals has changed. f_locals used to be a pure dict which was written back to the real locals on certain occasions (the most common one is returning from trace functions). The old behavior, when you remove a key from f_locals, if it was written back, was to set the local variable to None and generate a warning - a very inconsistent and confusing behavior.

    how do you generate the warning?

    I tried this on 3.12 and didn't see a warning, and the local didn't get set to None:

    import sys
    
    class A:
        pass
    
    
    def foo():
        a = A()
        f_locals = sys._getframe().f_locals
        del f_locals['a']
        print(a)
        print(f_locals)
    
    
    foo()
     graingert@conscientious  ~/projects  python3.12 -Werror demo.py
    <__main__.A object at 0x7ae782f40230>
    {}
     graingert@conscientious  ~/projects  python3.13 -Werror demo.py
    Traceback (most recent call last):
      File "/home/graingert/projects/demo.py", line 15, in <module>
        foo()
        ~~~^^
      File "/home/graingert/projects/demo.py", line 10, in foo
        del f_locals['a']
            ~~~~~~~~^^^^^
    TypeError: cannot remove variables from FrameLocalsProxy
    
  14. gaogaotiantian commented on Oct 16, 2024

    @gaogaotiantian
    gaogaotiantian
    on Oct 16, 2024
    Member
    More actions

    I tried this on 3.12 and didn't see a warning, and the local didn't get set to None:

    This is the case where the f_locals is not written back. Like I said, it was only written back on certain occasions, for example, when it returns from a trace function. And that's why we need to change it.

  15. 113908 commented on Oct 18, 2024

    @113908
    113908
    on Oct 18, 2024
    Author
    More actions

    Hello. Just checking back on this bug. Is there a plan to fix it and update the current Python 3.13 version with the fix? If so, when is that expected so I can reinstall Python 3.13? Thanks.

  16. gaogaotiantian commented on Oct 18, 2024

    @gaogaotiantian
    gaogaotiantian
    on Oct 18, 2024
    Member
    More actions

    The fix is in #125590 and it should be merged soon. We don't update the current version of 3.13, so 3.13.0 will be always like this without the fix. However, 3.13.1 should come up with the fix. It's estimated to be released two months after 3.13.0 so probably December.

    Reacted by Deana Garrott (113908)
  17. gaogaotiantian
    added a commit that references this issue on Oct 21, 2024

    gh-125590: Allow FrameLocalsProxy to delete and pop keys from extra l…

    5b7a872
  18. miss-islington
    added a commit that references this issue on Oct 21, 2024

    pythongh-125590: Allow FrameLocalsProxy to delete and pop keys from e…

    80ff0f0
  19. gaogaotiantian
    added a commit that references this issue on Oct 21, 2024

    [3.13] gh-125590: Allow FrameLocalsProxy to delete and pop keys from …

    829d650
  20. gaogaotiantian
    closed this as completedon Oct 21, 2024
  21. 113908 commented on Dec 3, 2024

    @113908
    113908
    on Dec 3, 2024
    Author
    More actions

    The fix is in #125590 and it should be merged soon. We don't update the current version of 3.13, so 3.13.0 will be always like this without the fix. However, 3.13.1 should come up with the fix. It's estimated to be released two months after 3.13.0 so probably December.

    Has version 3.13.1 been released yet?

  22. graingert commented on Dec 3, 2024

    @graingert
    graingert
    on Dec 3, 2024
    Contributor
    More actions

    Expected on the 12th https://peps.python.org/pep-0719/#bugfix-releases

  23. JelleZijlstra commented on Dec 3, 2024

    @JelleZijlstra
    JelleZijlstra
    on Dec 3, 2024
    Member
    More actions

    I believe the release is currently in progress, actually. The announcements should come shortly.

  24. graingert commented on Dec 4, 2024

    @graingert
    graingert
    on Dec 4, 2024
    Contributor
    More actions

    https://discuss.python.org/t/python-3-13-1-3-12-8-3-11-11-3-10-16-and-3-9-21-are-now-available/73214

    It's out

    Reacted by Edgar Ramírez Mondragón
  25. ebonnal
    added a commit that references this issue on Jan 12, 2025

    pythongh-125590: Allow FrameLocalsProxy to delete and pop keys from e…

    a926388
  26. seanbudd
    added a commit that references this issue on Aug 8, 2025

    Build with python 3.13 in parallel (#18611)

    145e5ee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.