Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-94808: Cover LOAD_GLOBAL for custom dict subtypes #96767

Merged
merged 3 commits into from
Nov 4, 2022

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Sep 12, 2022

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

  • The one where custom globals() dict subtype raises non KeyError:

    cpython/Python/ceval.c

    Lines 2445 to 2447 in 53a54b7

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

    cpython/Python/ceval.c

    Lines 2453 to 2457 in 53a54b7

    if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) {
    format_exc_check_arg(
    tstate, PyExc_NameError,
    NAME_ERROR_MSG, name);
    }

Copy link
Contributor

@mdboom mdboom left a comment

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.

def __getitem__(self, key):
raise setonlyerror

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done! Thanks!

@iritkatriel iritkatriel added needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes labels Nov 4, 2022
@iritkatriel iritkatriel merged commit 044bcc1 into python:main Nov 4, 2022
@miss-islington
Copy link
Contributor

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
@miss-islington
Copy link
Contributor

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
Copy link

GH-99091 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs backport to 3.10 only security fixes skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants