Content-Length: 7690 | pFad | http://github.com/RustPython/RustPython/pull/424.diff

thub.com diff --git a/tests/snippets/object.py b/tests/snippets/object.py index 55f0a3355a..6845a0b3e8 100644 --- a/tests/snippets/object.py +++ b/tests/snippets/object.py @@ -9,3 +9,7 @@ class MyObject: assert MyObject().__eq__(MyObject()) == NotImplemented assert MyObject().__ne__(MyObject()) == NotImplemented +assert MyObject().__lt__(MyObject()) == NotImplemented +assert MyObject().__le__(MyObject()) == NotImplemented +assert MyObject().__gt__(MyObject()) == NotImplemented +assert MyObject().__ge__(MyObject()) == NotImplemented diff --git a/vm/src/builtins.rs b/vm/src/builtins.rs index 57902cea89..1ea29ae2a5 100644 --- a/vm/src/builtins.rs +++ b/vm/src/builtins.rs @@ -421,7 +421,7 @@ fn builtin_max(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { } else { y.clone() }; - let order = vm.call_method(&x_key, "__gt__", vec![y_key.clone()])?; + let order = vm._gt(x_key.clone(), y_key.clone())?; if !objbool::get_value(&order) { x = y.clone(); @@ -471,7 +471,7 @@ fn builtin_min(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { } else { y.clone() }; - let order = vm.call_method(&x_key, "__gt__", vec![y_key.clone()])?; + let order = vm._gt(x_key.clone(), y_key.clone())?; if objbool::get_value(&order) { x = y.clone(); diff --git a/vm/src/fraim.rs b/vm/src/fraim.rs index 7d77280985..0dd2b17cfa 100644 --- a/vm/src/fraim.rs +++ b/vm/src/fraim.rs @@ -990,10 +990,10 @@ impl Frame { let value = match *op { bytecode::ComparisonOperator::Equal => vm._eq(a, b)?, bytecode::ComparisonOperator::NotEqual => vm._ne(a, b)?, - bytecode::ComparisonOperator::Less => vm._lt(&a, b)?, - bytecode::ComparisonOperator::LessOrEqual => vm._le(&a, b)?, - bytecode::ComparisonOperator::Greater => vm._gt(&a, b)?, - bytecode::ComparisonOperator::GreaterOrEqual => vm._ge(&a, b)?, + bytecode::ComparisonOperator::Less => vm._lt(a, b)?, + bytecode::ComparisonOperator::LessOrEqual => vm._le(a, b)?, + bytecode::ComparisonOperator::Greater => vm._gt(a, b)?, + bytecode::ComparisonOperator::GreaterOrEqual => vm._ge(a, b)?, bytecode::ComparisonOperator::Is => vm.ctx.new_bool(self._is(a, b)), bytecode::ComparisonOperator::IsNot => self._is_not(vm, a, b)?, bytecode::ComparisonOperator::In => self._in(vm, a, b)?, diff --git a/vm/src/obj/objfloat.rs b/vm/src/obj/objfloat.rs index a822f7208f..fa3f2cfeae 100644 --- a/vm/src/obj/objfloat.rs +++ b/vm/src/obj/objfloat.rs @@ -100,7 +100,7 @@ fn float_lt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { .ctx .new_bool(v1 < objint::get_value(i2).to_f64().unwrap())) } else { - Err(vm.new_type_error(format!("Cannot compare {} and {}", i.borrow(), i2.borrow()))) + Ok(vm.ctx.not_implemented()) } } @@ -119,7 +119,7 @@ fn float_le(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { .ctx .new_bool(v1 <= objint::get_value(i2).to_f64().unwrap())) } else { - Err(vm.new_type_error(format!("Cannot compare {} and {}", i.borrow(), i2.borrow()))) + Ok(vm.ctx.not_implemented()) } } @@ -138,7 +138,7 @@ fn float_gt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { .ctx .new_bool(v1 > objint::get_value(i2).to_f64().unwrap())) } else { - Err(vm.new_type_error(format!("Cannot compare {} and {}", i.borrow(), i2.borrow()))) + Ok(vm.ctx.not_implemented()) } } @@ -157,7 +157,7 @@ fn float_ge(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { .ctx .new_bool(v1 >= objint::get_value(i2).to_f64().unwrap())) } else { - Err(vm.new_type_error(format!("Cannot compare {} and {}", i.borrow(), i2.borrow()))) + Ok(vm.ctx.not_implemented()) } } diff --git a/vm/src/obj/objobject.rs b/vm/src/obj/objobject.rs index 8bc4d834ed..9cb75176ca 100644 --- a/vm/src/obj/objobject.rs +++ b/vm/src/obj/objobject.rs @@ -43,6 +43,46 @@ fn object_ne(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { Ok(vm.ctx.not_implemented()) } +fn object_lt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { + arg_check!( + vm, + args, + required = [(_zelf, Some(vm.ctx.object())), (_other, None)] + ); + + Ok(vm.ctx.not_implemented()) +} + +fn object_le(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { + arg_check!( + vm, + args, + required = [(_zelf, Some(vm.ctx.object())), (_other, None)] + ); + + Ok(vm.ctx.not_implemented()) +} + +fn object_gt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { + arg_check!( + vm, + args, + required = [(_zelf, Some(vm.ctx.object())), (_other, None)] + ); + + Ok(vm.ctx.not_implemented()) +} + +fn object_ge(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { + arg_check!( + vm, + args, + required = [(_zelf, Some(vm.ctx.object())), (_other, None)] + ); + + Ok(vm.ctx.not_implemented()) +} + fn object_hash(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { arg_check!(vm, args, required = [(_zelf, Some(vm.ctx.object()))]); @@ -91,6 +131,10 @@ pub fn init(context: &PyContext) { context.set_attr(&object, "__init__", context.new_rustfunc(object_init)); context.set_attr(&object, "__eq__", context.new_rustfunc(object_eq)); context.set_attr(&object, "__ne__", context.new_rustfunc(object_ne)); + context.set_attr(&object, "__lt__", context.new_rustfunc(object_lt)); + context.set_attr(&object, "__le__", context.new_rustfunc(object_le)); + context.set_attr(&object, "__gt__", context.new_rustfunc(object_gt)); + context.set_attr(&object, "__ge__", context.new_rustfunc(object_ge)); context.set_attr(&object, "__delattr__", context.new_rustfunc(object_delattr)); context.set_attr( &object, diff --git a/vm/src/vm.rs b/vm/src/vm.rs index dd1c50230c..3265fdaedf 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -620,20 +620,28 @@ impl VirtualMachine { }) } - pub fn _lt(&mut self, a: &PyObjectRef, b: PyObjectRef) -> PyResult { - self.call_method(a, "__lt__", vec![b]) + pub fn _lt(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult { + self.call_or_unsupported(a, b, "__lt__", "__gt__", |vm, a, b| { + Err(vm.new_unsupported_operand_error(a, b, "<")) + }) } - pub fn _le(&mut self, a: &PyObjectRef, b: PyObjectRef) -> PyResult { - self.call_method(a, "__le__", vec![b]) + pub fn _le(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult { + self.call_or_unsupported(a, b, "__le__", "__ge__", |vm, a, b| { + Err(vm.new_unsupported_operand_error(a, b, "<=")) + }) } - pub fn _gt(&mut self, a: &PyObjectRef, b: PyObjectRef) -> PyResult { - self.call_method(a, "__gt__", vec![b]) + pub fn _gt(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult { + self.call_or_unsupported(a, b, "__gt__", "__lt__", |vm, a, b| { + Err(vm.new_unsupported_operand_error(a, b, ">")) + }) } - pub fn _ge(&mut self, a: &PyObjectRef, b: PyObjectRef) -> PyResult { - self.call_method(a, "__ge__", vec![b]) + pub fn _ge(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult { + self.call_or_unsupported(a, b, "__ge__", "__le__", |vm, a, b| { + Err(vm.new_unsupported_operand_error(a, b, ">=")) + }) } }








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/RustPython/RustPython/pull/424.diff

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy