Skip to content

Comments

gh-141510: Check argument in PyDict_Contains()#145083

Merged
vstinner merged 2 commits intopython:mainfrom
vstinner:frozendict_dict_contains
Feb 21, 2026
Merged

gh-141510: Check argument in PyDict_Contains()#145083
vstinner merged 2 commits intopython:mainfrom
vstinner:frozendict_dict_contains

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Feb 21, 2026

PyDict_Contains() and PyDict_ContainsString() now fail with SystemError if the first argument is not a dict, frozendict, dict subclass or frozendict subclass.

PyDict_Contains() and PyDict_ContainsString() now fail with
SystemError if the first argument is not a dict, frozendict, dict
subclass or frozendict subclass.
Comment on lines +5004 to +5007
if (!PyAnyDict_Check(op)) {
PyErr_BadInternalCall();
return -1;
}
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind adding a versionchanged for this in the docs? This looks good otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

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

We do not document SystemError errors in the documentation. It's not really part of the API, but provided to be kind with developers.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure that's necessarily a good thing. It's helpful for extension authors to know whether they need to validate their input.

Copy link
Member Author

Choose a reason for hiding this comment

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

They always need to validate their input. You're not supposed to hit SystemError in regular code.

@vstinner vstinner merged commit c9380ae into python:main Feb 21, 2026
45 checks passed
@vstinner vstinner deleted the frozendict_dict_contains branch February 21, 2026 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants