◐ Shell
clean mode source ↗

gh-94808: Cover `LOAD_GLOBAL` for custom dict subtypes by sobolevn · Pull Request #96767 · python/cpython

@sobolevn

I've covered several missing conditions in TARGET(LOAD_GLOBAL):

  • The one where custom globals() dict subtype raises non KeyError:
    if (!_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
    goto error;
    }
  • Similar case where __builtins__ dict subtype raises non KeyError:
  • Regular NameError in a custom __builtins__ dict subtype:
    if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
    format_exc_check_arg(
    tstate, PyExc_NameError,
    NAME_ERROR_MSG, name);
    }

mdboom

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the contribution.

iritkatriel

def __getitem__(self, key):
raise setonlyerror

class customdict(dict): # this one should not do anything fancy

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be defined just before the test that uses it (below). Ideally this function would be broken up - it's testing a lot of things.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Thanks!

iritkatriel

@miss-islington

Thanks @sobolevn for the PR, and @iritkatriel for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request

Nov 4, 2022
…H-96767)

(cherry picked from commit 044bcc1)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>

@miss-islington

Sorry, @sobolevn and @iritkatriel, I could not cleanly backport this to 3.10 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 044bcc1771fe7e2f8eba21793a72ba15e75e6715 3.10

@bedevere-bot

iritkatriel pushed a commit that referenced this pull request

Nov 4, 2022