Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Lib/test/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,6 @@ def test_copy(self):
self.assertEqual(view['key1'], 70)
self.assertEqual(copy['key1'], 27)

@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: unsupported operand type(s) for |: 'dict' and 'mappingproxy'
def test_union(self):
mapping = {'a': 0, 'b': 1, 'c': 2}
view = self.mappingproxy(mapping)
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_userdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ class G(collections.UserDict):

test_repr_deep = mapping_tests.TestHashMappingProtocol.test_repr_deep

@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: unsupported operand type(s) for |: 'UserDict' and 'mappingproxy'
def test_mixed_or(self):
for t in UserDict, dict, types.MappingProxyType:
with self.subTest(t.__name__):
Expand Down
18 changes: 13 additions & 5 deletions crates/vm/src/builtins/mappingproxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,19 @@ impl AsNumber for PyMappingProxy {
fn as_number() -> &'static PyNumberMethods {
static AS_NUMBER: PyNumberMethods = PyNumberMethods {
or: Some(|a, b, vm| {
if let Some(a) = a.downcast_ref::<PyMappingProxy>() {
a.__or__(b.to_pyobject(vm), vm)
} else {
Ok(vm.ctx.not_implemented())
}
// Mirror CPython's mappingproxy_or: when either side is a
// mappingproxy, unwrap to its underlying mapping and delegate
// to PyNumber_Or so `dict | mp`, `mp | dict`, and `mp | mp`
// all produce a `dict` result.
let a_obj = match a.downcast_ref::<PyMappingProxy>() {
Some(mp) => mp.copy(vm)?,
None => a.to_pyobject(vm),
};
let b_obj = match b.downcast_ref::<PyMappingProxy>() {
Some(mp) => mp.copy(vm)?,
None => b.to_pyobject(vm),
};
vm._or(a_obj.as_ref(), b_obj.as_ref())
}),
inplace_or: Some(|a, b, vm| {
if let Some(a) = a.downcast_ref::<PyMappingProxy>() {
Expand Down