Skip to content

gh-110525: Add CAPI tests for set and frozenset objects #110526

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

Merged
merged 4 commits into from
Oct 9, 2023

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Oct 8, 2023

@sobolevn sobolevn requested a review from a team as a code owner October 8, 2023 20:33
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Nice.

Please test also with non-hashable items, non-set as the first argument, NULLs for any argument. If some call crashes, add a comment.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

I was never comfortable with _testcapi having fun with changing C API names. We cannot simply use PySet_New() name in _testcapi and in the test? I would make it more obvious that the test is on... PySet_New().


class TestSetCAPI(unittest.TestCase):
def assertImmutable(self, action, *args):
self.assertRaises(SystemError, action, frozenset(), *args)
Copy link
Member

Choose a reason for hiding this comment

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

SystemError? That's a surprising error. Usually, it's used when the C API is misused, like passing NULL or the wrong type. frozenset is a "wrong type" here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, immutable frozenset is a wrong type for mutation-based functions :)

@sobolevn
Copy link
Member Author

sobolevn commented Oct 9, 2023

I was never comfortable with _testcapi having fun with changing C API names. We cannot simply use PySet_New() name in _testcapi and in the test?

I think that this is intentional, because we don't really call PySet_Check, we call set_check intermediate function which changes some behavior compared to PySet_Check. For example, it converts None to NULL (so we can test passing NULL easier).

So, I would prefer to keep this naming convention.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you @sobolevn for your PR.

@serhiy-storchaka serhiy-storchaka added the needs backport to 3.12 only security fixes label Oct 9, 2023
@serhiy-storchaka serhiy-storchaka merged commit c49edd7 into python:main Oct 9, 2023
@miss-islington
Copy link
Contributor

Thanks @sobolevn for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @sobolevn and @serhiy-storchaka, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker c49edd7d9c5395a6a6696a4846f56bc8b2b22792 3.12

@sobolevn
Copy link
Member Author

sobolevn commented Oct 9, 2023

Should I do a manual backport?

@serhiy-storchaka
Copy link
Member

It would be nice. Otherwise I will do it.

sobolevn added a commit to sobolevn/cpython that referenced this pull request Oct 9, 2023
…ythonGH-110526).

(cherry picked from commit c49edd7)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@bedevere-app
Copy link

bedevere-app bot commented Oct 9, 2023

GH-110547 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Oct 9, 2023
serhiy-storchaka pushed a commit that referenced this pull request Oct 9, 2023
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
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.

4 participants