Skip to content

Commit 33b420f

Browse files
authored
Merge pull request RustPython#3989 from TwoPair/union-or-types
Update cmp of `PyUnion`
2 parents f40a620 + 5480f4c commit 33b420f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Lib/test/test_types.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,6 @@ def test_none_type(self):
637637

638638
class UnionTests(unittest.TestCase):
639639

640-
# TODO: RUSTPYTHON
641-
@unittest.expectedFailure
642640
def test_or_types_operator(self):
643641
self.assertEqual(int | str, typing.Union[int, str])
644642
self.assertNotEqual(int | list, typing.Union[int, str])

vm/src/builtins/union.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,14 @@ impl Comparable for PyUnion {
271271
) -> PyResult<PyComparisonValue> {
272272
op.eq_only(|| {
273273
let other = class_or_notimplemented!(Self, other);
274+
let a = PyFrozenSet::from_iter(vm, zelf.args.into_iter().cloned())?;
275+
let b = PyFrozenSet::from_iter(vm, other.args.into_iter().cloned())?;
274276
Ok(PyComparisonValue::Implemented(
275-
zelf.args()
276-
.rich_compare_bool(other.args().as_ref(), PyComparisonOp::Eq, vm)?,
277+
a.into_pyobject(vm).as_object().rich_compare_bool(
278+
b.into_pyobject(vm).as_object(),
279+
PyComparisonOp::Eq,
280+
vm,
281+
)?,
277282
))
278283
})
279284
}

0 commit comments

Comments
 (0)