Skip to content

Commit f40a620

Browse files
authored
Merge pull request RustPython#3990 from moreal/correct-union-hash
Correct union hash
2 parents d236067 + 5658a6b commit f40a620

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

Lib/test/test_types.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,6 @@ def test_or_types_operator(self):
703703
y.__args__ = [str, int]
704704
self.assertEqual(x, y)
705705

706-
# TODO: RUSTPYTHON
707-
@unittest.expectedFailure
708706
def test_hash(self):
709707
self.assertEqual(hash(int | str), hash(str | int))
710708
self.assertEqual(hash(int | str), hash(typing.Union[int, str]))

vm/src/builtins/union.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
convert::ToPyObject,
77
function::PyComparisonValue,
88
protocol::PyMappingMethods,
9-
types::{AsMapping, Comparable, GetAttr, Hashable, Iterable, PyComparisonOp},
9+
types::{AsMapping, Comparable, GetAttr, Hashable, PyComparisonOp},
1010
AsObject, Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
1111
VirtualMachine,
1212
};
@@ -282,8 +282,7 @@ impl Comparable for PyUnion {
282282
impl Hashable for PyUnion {
283283
#[inline]
284284
fn hash(zelf: &crate::Py<Self>, vm: &VirtualMachine) -> PyResult<hash::PyHash> {
285-
let it = PyTuple::iter(zelf.args.clone(), vm);
286-
let set = PyFrozenSet::from_iter(vm, it)?;
285+
let set = PyFrozenSet::from_iter(vm, zelf.args.into_iter().cloned())?;
287286
PyFrozenSet::hash(&set.into_ref(vm), vm)
288287
}
289288
}

0 commit comments

Comments
 (0)