mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-44646: Fix the hash of the union type. (GH-27179) (#27180)
It no longer depends on the order of arguments.
hash(int | str) == hash(str | int)
Co-authored-by: Jack DeVries <58614260+jdevries3133@users.noreply.github.com>
(cherry picked from commit aeaa553d65
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
6aa59c68dc
commit
705988056e
3 changed files with 12 additions and 4 deletions
|
@ -33,11 +33,13 @@ static Py_hash_t
|
|||
union_hash(PyObject *self)
|
||||
{
|
||||
unionobject *alias = (unionobject *)self;
|
||||
Py_hash_t h1 = PyObject_Hash(alias->args);
|
||||
if (h1 == -1) {
|
||||
return -1;
|
||||
PyObject *args = PyFrozenSet_New(alias->args);
|
||||
if (args == NULL) {
|
||||
return (Py_hash_t)-1;
|
||||
}
|
||||
return h1;
|
||||
Py_hash_t hash = PyObject_Hash(args);
|
||||
Py_DECREF(args);
|
||||
return hash;
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue