Skip to content

gh-110525: Add tests for internal set CAPI #110630

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 10, 2023

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Oct 10, 2023

NULLABLE(set);

rc = _PySet_NextEntry(set, &pos, &item, &hash);
if (rc == 1) {
Copy link
Member

Choose a reason for hiding this comment

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

What if it returns 2 or -2?

Suggested change
if (rc == 1) {
if (rc != 0 && rc != -1) {

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I don't understand this one. Right now it is defined as:

cpython/Objects/setobject.c

Lines 2332 to 2346 in 66a9b10

int
_PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash)
{
setentry *entry;
if (!PyAnySet_Check(set)) {
PyErr_BadInternalCall();
return -1;
}
if (set_next((PySetObject *)set, pos, &entry) == 0)
return 0;
*key = entry->key;
*hash = entry->hash;
return 1;
}

It cannot return anything except [-1, 0, 1].
Do you mean that it can return something other than [-1, 0, 1] in the future?
I think that our test case must catch this change and be adapted if needed.

This function is not documented currently.

Copy link
Member

@serhiy-storchaka serhiy-storchaka Oct 10, 2023

Choose a reason for hiding this comment

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

The purpose of the test is to verify our assumptions (that it cannot return anything except [-1, 0, 1]). Otherwise there would not be need of tests.

In future a new return can be added in the code, or refactoring can lead to returning non-initialized variable in rare case. The wrapper will successfully return None.

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it, I used an assertion, which is more readable in my opinion 👍

@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 9cfb4e0d1ebf2900c19ee07697818c621f46cc3d 3.12

@serhiy-storchaka serhiy-storchaka removed the request for review from a team October 10, 2023 16:00
@sobolevn
Copy link
Member Author

Working on a backport

@sobolevn
Copy link
Member Author

@serhiy-storchaka looks like #108787 never got backported, so we don't have the same file structure on 3.12

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.

3 participants