Skip to content

Instantly share code, notes, and snippets.

@devdanzin
Created March 18, 2026 10:06
Show Gist options
  • Select an option

  • Save devdanzin/0a3dd4f8fb0fb144efcc02c3e86665a5 to your computer and use it in GitHub Desktop.

Select an option

Save devdanzin/0a3dd4f8fb0fb144efcc02c3e86665a5 to your computer and use it in GitHub Desktop.
frameobject.c: FrameLocalsProxy swallows and overwrites real errors

frameobject.c: FrameLocalsProxy swallows and overwrites real errors

Summary

Two bugs:

  1. framelocalsproxy_inplace_or (line 573) returns Py_NotImplemented instead of NULL when merge fails → exceptions silently discarded.
  2. framelocalsproxy_update (line 730) unconditionally replaces any exception with TypeError.

Reproducer

import sys
frame = sys._getframe()
locs = frame.f_locals

class BadDict(dict):
    def keys(self):
        raise RuntimeError("keys() failed!")

# Bug 1: |= swallows the error
try:
    locs |= BadDict()
    print("|= silently swallowed RuntimeError (BUG)")
except RuntimeError:
    print("|= correctly propagated")

# Bug 2: .update() replaces RuntimeError with TypeError
try:
    locs.update(BadDict())
except TypeError:
    print("update() masked RuntimeError as TypeError (BUG)")
except RuntimeError:
    print("update() correctly propagated")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment