Skip to content

Commit 057a225

Browse files
Move delegation of __ne__ to __eq__ out of objobject
1 parent a510aed commit 057a225

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

tests/snippets/object.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class MyObject:
2+
pass
3+
4+
assert not MyObject() == MyObject()
5+
assert MyObject() != MyObject()
6+
myobj = MyObject()
7+
assert myobj == myobj
8+
assert not myobj != myobj
9+
10+
assert MyObject().__eq__(MyObject()) == NotImplemented
11+
assert MyObject().__ne__(MyObject()) == NotImplemented

vm/src/obj/objobject.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use super::super::pyobject::{
33
TypeProtocol,
44
};
55
use super::super::vm::VirtualMachine;
6-
use super::objbool;
76
use super::objstr;
87
use super::objtype;
98
use std::cell::RefCell;
@@ -29,20 +28,19 @@ fn object_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
2928
arg_check!(
3029
vm,
3130
args,
32-
required = [(zelf, Some(vm.ctx.object())), (other, None)]
31+
required = [(_zelf, Some(vm.ctx.object())), (_other, None)]
3332
);
34-
Ok(vm.ctx.new_bool(zelf.is(other)))
33+
Ok(vm.ctx.not_implemented())
3534
}
3635

3736
fn object_ne(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
3837
arg_check!(
3938
vm,
4039
args,
41-
required = [(zelf, Some(vm.ctx.object())), (other, None)]
40+
required = [(_zelf, Some(vm.ctx.object())), (_other, None)]
4241
);
4342

44-
let eq = vm._eq(zelf.clone(), other.clone())?;
45-
objbool::not(vm, &eq)
43+
Ok(vm.ctx.not_implemented())
4644
}
4745

4846
fn object_hash(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {

vm/src/vm.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::sync::{Mutex, MutexGuard};
1313
use super::builtins;
1414
use super::bytecode;
1515
use super::frame::Frame;
16+
use super::obj::objbool;
1617
use super::obj::objcode;
1718
use super::obj::objgenerator;
1819
use super::obj::objiter;
@@ -616,7 +617,8 @@ impl VirtualMachine {
616617

617618
pub fn _ne(&mut self, a: PyObjectRef, b: PyObjectRef) -> PyResult {
618619
self.call_or_unsupported(a, b, "__ne__", "__ne__", |vm, a, b| {
619-
Ok(vm.new_bool(!a.is(&b)))
620+
let eq = vm._eq(a, b)?;
621+
objbool::not(vm, &eq)
620622
})
621623
}
622624

0 commit comments

Comments
 (0)