Merge pull request #3990 from moreal/correct-union-hash

Correct union hash
This commit is contained in:
Jeong YunWon
2022-08-02 16:00:32 +09:00
committed by GitHub
2 changed files with 2 additions and 5 deletions

View File

@@ -703,8 +703,6 @@ class UnionTests(unittest.TestCase):
y.__args__ = [str, int]
self.assertEqual(x, y)
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_hash(self):
self.assertEqual(hash(int | str), hash(str | int))
self.assertEqual(hash(int | str), hash(typing.Union[int, str]))

View File

@@ -6,7 +6,7 @@ use crate::{
convert::ToPyObject,
function::PyComparisonValue,
protocol::PyMappingMethods,
types::{AsMapping, Comparable, GetAttr, Hashable, Iterable, PyComparisonOp},
types::{AsMapping, Comparable, GetAttr, Hashable, PyComparisonOp},
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
VirtualMachine,
};
@@ -282,8 +282,7 @@ impl Comparable for PyUnion {
impl Hashable for PyUnion {
#[inline]
fn hash(zelf: &crate::Py<Self>, vm: &VirtualMachine) -> PyResult<hash::PyHash> {
let it = PyTuple::iter(zelf.args.clone(), vm);
let set = PyFrozenSet::from_iter(vm, it)?;
let set = PyFrozenSet::from_iter(vm, zelf.args.into_iter().cloned())?;
PyFrozenSet::hash(&set.into_ref(vm), vm)
}
}