mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 10:44:36 +08:00
Fix None.__ne__ bug
This commit is contained in:
1 parent
21c5eae717
commit
bf985c8ac6
2 files changed
+4
-27
No files matched your search
@@ -22,4 +22,4 @@ assert type(None)() is None
|
||||
assert None.__eq__(3) is NotImplemented
|
||||
assert None.__ne__(3) is NotImplemented
|
||||
assert None.__eq__(None) is True
|
||||
assert None.__ne__(None) is NotImplemented
|
||||
assert None.__ne__(None) is False
|
||||
@@ -2,10 +2,9 @@ use super::{PyStrRef, PyType, PyTypeRef};
|
||||
use crate::{
|
||||
class::PyClassImpl,
|
||||
convert::ToPyObject,
|
||||
function::{PyArithmeticValue, PyComparisonValue},
|
||||
protocol::PyNumberMethods,
|
||||
types::{AsNumber, Comparable, Constructor, PyComparisonOp, Representable},
|
||||
Context, Py, PyObject, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
types::{AsNumber, Constructor, Representable},
|
||||
Context, Py, PyObjectRef, PyPayload, PyResult, VirtualMachine,
|
||||
};
|
||||
|
||||
#[pyclass(module = false, name = "NoneType")]
|
||||
@@ -43,7 +42,7 @@ impl Constructor for PyNone {
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(with(Constructor, Comparable, AsNumber, Representable))]
|
||||
#[pyclass(with(Constructor, AsNumber, Representable))]
|
||||
impl PyNone {
|
||||
#[pymethod(magic)]
|
||||
fn bool(&self) -> bool {
|
||||
@@ -73,28 +72,6 @@ impl AsNumber for PyNone {
|
||||
}
|
||||
}
|
||||
|
||||
impl Comparable for PyNone {
|
||||
fn cmp(
|
||||
_zelf: &Py<Self>,
|
||||
other: &PyObject,
|
||||
op: PyComparisonOp,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<PyComparisonValue> {
|
||||
let value = match op {
|
||||
PyComparisonOp::Eq => {
|
||||
if vm.is_none(other) {
|
||||
PyArithmeticValue::Implemented(true)
|
||||
} else {
|
||||
PyArithmeticValue::NotImplemented
|
||||
}
|
||||
}
|
||||
_ => PyComparisonValue::NotImplemented,
|
||||
};
|
||||
|
||||
Ok(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[pyclass(module = false, name = "NotImplementedType")]
|
||||
#[derive(Debug)]
|
||||
pub struct PyNotImplemented;
|
||||
|
||||
Reference in new issue
Block a user