-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
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
Conversation
NULLABLE(set); | ||
|
||
rc = _PySet_NextEntry(set, &pos, &item, &hash); | ||
if (rc == 1) { |
There was a problem hiding this comment.
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?
if (rc == 1) { | |
if (rc != 0 && rc != -1) { |
There was a problem hiding this comment.
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:
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👍
Thanks @sobolevn for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
Sorry, @sobolevn and @serhiy-storchaka, I could not cleanly backport this to
|
Working on a backport |
@serhiy-storchaka looks like #108787 never got backported, so we don't have the same file structure on 3.12 |
set
andfrozenset
#110525