Skip to content

Commit 488e368

Browse files
committed
Fix None.__ne__ bug
1 parent 5aff28b commit 488e368

File tree

2 files changed

+4
-27
lines changed

2 files changed

+4
-27
lines changed

extra_tests/snippets/builtin_none.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ def none2():
2222
assert None.__eq__(3) is NotImplemented
2323
assert None.__ne__(3) is NotImplemented
2424
assert None.__eq__(None) is True
25-
assert None.__ne__(None) is NotImplemented
25+
assert None.__ne__(None) is False

vm/src/builtins/singletons.rs

+3-26
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ use super::{PyStrRef, PyType, PyTypeRef};
22
use crate::{
33
class::PyClassImpl,
44
convert::ToPyObject,
5-
function::{PyArithmeticValue, PyComparisonValue},
65
protocol::PyNumberMethods,
7-
types::{AsNumber, Comparable, Constructor, PyComparisonOp, Representable},
8-
Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine,
6+
types::{AsNumber, Constructor, Representable},
7+
Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
98
};
109

1110
#[pyclass(module = false, name = "NoneType")]
@@ -43,7 +42,7 @@ impl Constructor for PyNone {
4342
}
4443
}
4544

46-
#[pyclass(with(Constructor, Comparable, AsNumber, Representable))]
45+
#[pyclass(with(Constructor, AsNumber, Representable))]
4746
impl PyNone {
4847
#[pymethod(magic)]
4948
fn bool(&self) -> bool {
@@ -73,28 +72,6 @@ impl AsNumber for PyNone {
7372
}
7473
}
7574

76-
impl Comparable for PyNone {
77-
fn cmp(
78-
_zelf: &Py<Self>,
79-
other: &PyObject,
80-
op: PyComparisonOp,
81-
vm: &VirtualMachine,
82-
) -> PyResult<PyComparisonValue> {
83-
let value = match op {
84-
PyComparisonOp::Eq => {
85-
if vm.is_none(other) {
86-
PyArithmeticValue::Implemented(true)
87-
} else {
88-
PyArithmeticValue::NotImplemented
89-
}
90-
}
91-
_ => PyComparisonValue::NotImplemented,
92-
};
93-
94-
Ok(value)
95-
}
96-
}
97-
9875
#[pyclass(module = false, name = "NotImplementedType")]
9976
#[derive(Debug)]
10077
pub struct PyNotImplemented;

0 commit comments

Comments
 (0)