mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Merge pull request #3990 from moreal/correct-union-hash
Correct union hash
This commit is contained in:
2
Lib/test/test_types.py
vendored
2
Lib/test/test_types.py
vendored
@@ -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]))
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user