mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Merge pull request #3568 from youknowone/fix-priority
Fix reflection operator priority for subtypes
This commit is contained in:
2
Lib/test/test_collections.py
vendored
2
Lib/test/test_collections.py
vendored
@@ -248,8 +248,6 @@ class TestChainMap(unittest.TestCase):
|
||||
for k, v in dict(a=1, B=20, C=30, z=100).items(): # check get
|
||||
self.assertEqual(d.get(k, 100), v)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_union_operators(self):
|
||||
cm1 = ChainMap(dict(a=1, b=2), dict(c=3, d=4))
|
||||
cm2 = ChainMap(dict(a=10, e=5), dict(b=20, d=4))
|
||||
|
||||
6
Lib/test/test_enum.py
vendored
6
Lib/test/test_enum.py
vendored
@@ -2637,8 +2637,6 @@ class TestIntFlag(unittest.TestCase):
|
||||
self.assertEqual(format(Perm.R, ''), '4')
|
||||
self.assertEqual(format(Perm.R | Perm.X, ''), '5')
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_or(self):
|
||||
Perm = self.Perm
|
||||
for i in Perm:
|
||||
@@ -2660,8 +2658,6 @@ class TestIntFlag(unittest.TestCase):
|
||||
Open = self.Open
|
||||
self.assertIs(Open.RO | Open.CE, Open.CE)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_and(self):
|
||||
Perm = self.Perm
|
||||
RW = Perm.R | Perm.W
|
||||
@@ -2688,8 +2684,6 @@ class TestIntFlag(unittest.TestCase):
|
||||
Open = self.Open
|
||||
self.assertIs(Open.RO & Open.CE, Open.RO)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_xor(self):
|
||||
Perm = self.Perm
|
||||
for i in Perm:
|
||||
|
||||
2
Lib/test/test_unicode.py
vendored
2
Lib/test/test_unicode.py
vendored
@@ -1501,8 +1501,6 @@ class UnicodeTest(string_tests.CommonTest,
|
||||
with self.assertRaises(ValueError):
|
||||
result = format_string % 2.34
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_issue28598_strsubclass_rhs(self):
|
||||
# A subclass of str with an __rmod__ method should be able to hook
|
||||
# into the % operator
|
||||
|
||||
13
vm/src/vm.rs
13
vm/src/vm.rs
@@ -1333,6 +1333,19 @@ impl VirtualMachine {
|
||||
reflection: &str,
|
||||
unsupported: fn(&VirtualMachine, &PyObject, &PyObject) -> PyResult,
|
||||
) -> PyResult {
|
||||
if rhs.isinstance(&lhs.clone_class()) {
|
||||
let lop = lhs.get_class_attr(reflection);
|
||||
let rop = rhs.get_class_attr(reflection);
|
||||
if let Some((lop, rop)) = lop.zip(rop) {
|
||||
if !lop.is(&rop) {
|
||||
if let Ok(r) = self.call_or_unsupported(rhs, lhs, reflection, |vm, _, _| {
|
||||
Err(vm.new_exception_empty(vm.ctx.exceptions.exception_type.clone()))
|
||||
}) {
|
||||
return Ok(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Try to call the default method
|
||||
self.call_or_unsupported(lhs, rhs, default, move |vm, lhs, rhs| {
|
||||
// Try to call the reflection method
|
||||
|
||||
Reference in New Issue
Block a user