mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Merge pull request #2848 from voidsatisfaction/fix-dict-or-ror-ior-return-notimplemented
Fix make dict.{__or__,__ror__,__ior__} with other types return NotImplemented
This commit is contained in:
@@ -42,27 +42,15 @@ def test_dunion_ror0():
|
||||
def test_dunion_other_types():
|
||||
def perf_test_or(other_obj):
|
||||
d={1:2}
|
||||
try:
|
||||
d.__or__(other_obj)
|
||||
except:
|
||||
return True
|
||||
return False
|
||||
return d.__or__(other_obj) is NotImplemented
|
||||
|
||||
def perf_test_ior(other_obj):
|
||||
d={1:2}
|
||||
try:
|
||||
d.__ior__(other_obj)
|
||||
except:
|
||||
return True
|
||||
return False
|
||||
return d.__ior__(other_obj) is NotImplemented
|
||||
|
||||
def perf_test_ror(other_obj):
|
||||
d={1:2}
|
||||
try:
|
||||
d.__ror__(other_obj)
|
||||
except:
|
||||
return True
|
||||
return False
|
||||
return d.__ror__(other_obj) is NotImplemented
|
||||
|
||||
test_fct={'__or__':perf_test_or, '__ror__':perf_test_ror, '__ior__':perf_test_ior}
|
||||
others=['FooBar', 42, [36], set([19]), ['aa'], None]
|
||||
|
||||
@@ -316,29 +316,29 @@ impl PyDict {
|
||||
PyDict::merge_dict(&zelf.entries, other, vm)?;
|
||||
return Ok(zelf.into_object());
|
||||
}
|
||||
Err(vm.new_type_error("__ior__ not implemented for non-dict type".to_owned()))
|
||||
Ok(vm.ctx.not_implemented())
|
||||
}
|
||||
|
||||
#[pymethod(name = "__ror__")]
|
||||
fn ror(zelf: PyRef<Self>, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyDict> {
|
||||
fn ror(zelf: PyRef<Self>, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
let dicted: Result<PyDictRef, _> = other.downcast();
|
||||
if let Ok(other) = dicted {
|
||||
let other_cp = other.copy();
|
||||
PyDict::merge_dict(&other_cp.entries, zelf, vm)?;
|
||||
return Ok(other_cp);
|
||||
return Ok(other_cp.into_object(vm));
|
||||
}
|
||||
Err(vm.new_type_error("__ror__ not implemented for non-dict type".to_owned()))
|
||||
Ok(vm.ctx.not_implemented())
|
||||
}
|
||||
|
||||
#[pymethod(name = "__or__")]
|
||||
fn or(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyDict> {
|
||||
fn or(&self, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
let dicted: Result<PyDictRef, _> = other.downcast();
|
||||
if let Ok(other) = dicted {
|
||||
let self_cp = self.copy();
|
||||
PyDict::merge_dict(&self_cp.entries, other, vm)?;
|
||||
return Ok(self_cp);
|
||||
return Ok(self_cp.into_object(vm));
|
||||
}
|
||||
Err(vm.new_type_error("__or__ not implemented for non-dict type".to_owned()))
|
||||
Ok(vm.ctx.not_implemented())
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
|
||||
Reference in New Issue
Block a user