mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Add NotImplemented built-in constant
This commit is contained in:
@@ -14,7 +14,7 @@ assert not complex(1, 1).__eq__(1.0)
|
||||
assert not complex(1, 0).__eq__(1.5)
|
||||
assert complex(1, 0).__eq__(True)
|
||||
assert not complex(1, 2).__eq__(complex(1, 1))
|
||||
#assert complex(1, 2).__eq__('foo') == NotImplemented
|
||||
assert complex(1, 2).__eq__('foo') == NotImplemented
|
||||
|
||||
# __neg__
|
||||
|
||||
|
||||
@@ -685,6 +685,9 @@ pub fn make_module(ctx: &PyContext) -> PyObjectRef {
|
||||
ctx.set_attr(&py_mod, "type", ctx.type_type());
|
||||
ctx.set_attr(&py_mod, "zip", ctx.zip_type());
|
||||
|
||||
// Constants
|
||||
ctx.set_attr(&py_mod, "NotImplemented", ctx.not_implemented.clone());
|
||||
|
||||
// Exceptions:
|
||||
ctx.set_attr(
|
||||
&py_mod,
|
||||
|
||||
@@ -112,6 +112,7 @@ fn complex_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
);
|
||||
|
||||
let z = get_value(zelf);
|
||||
|
||||
let result = if objtype::isinstance(other, &vm.ctx.complex_type()) {
|
||||
z == get_value(other)
|
||||
} else if objtype::isinstance(other, &vm.ctx.int_type()) {
|
||||
@@ -122,8 +123,9 @@ fn complex_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
} else if objtype::isinstance(other, &vm.ctx.float_type()) {
|
||||
z.im == 0.0 && z.re == objfloat::get_value(other)
|
||||
} else {
|
||||
false
|
||||
return Ok(vm.ctx.not_implemented());
|
||||
};
|
||||
|
||||
Ok(vm.ctx.new_bool(result))
|
||||
}
|
||||
|
||||
|
||||
@@ -130,6 +130,7 @@ pub struct PyContext {
|
||||
pub map_type: PyObjectRef,
|
||||
pub memoryview_type: PyObjectRef,
|
||||
pub none: PyObjectRef,
|
||||
pub not_implemented: PyObjectRef,
|
||||
pub tuple_type: PyObjectRef,
|
||||
pub set_type: PyObjectRef,
|
||||
pub staticmethod_type: PyObjectRef,
|
||||
@@ -223,6 +224,11 @@ impl PyContext {
|
||||
create_type("NoneType", &type_type, &object_type, &dict_type),
|
||||
);
|
||||
|
||||
let not_implemented = PyObject::new(
|
||||
PyObjectPayload::NotImplemented,
|
||||
create_type("NotImplementedType", &type_type, &object_type, &dict_type),
|
||||
);
|
||||
|
||||
let true_value = PyObject::new(
|
||||
PyObjectPayload::Integer { value: One::one() },
|
||||
bool_type.clone(),
|
||||
@@ -258,6 +264,7 @@ impl PyContext {
|
||||
zip_type,
|
||||
dict_type,
|
||||
none,
|
||||
not_implemented,
|
||||
str_type,
|
||||
range_type,
|
||||
object: object_type,
|
||||
@@ -423,6 +430,9 @@ impl PyContext {
|
||||
pub fn none(&self) -> PyObjectRef {
|
||||
self.none.clone()
|
||||
}
|
||||
pub fn not_implemented(&self) -> PyObjectRef {
|
||||
self.not_implemented.clone()
|
||||
}
|
||||
pub fn object(&self) -> PyObjectRef {
|
||||
self.object.clone()
|
||||
}
|
||||
@@ -956,6 +966,7 @@ pub enum PyObjectPayload {
|
||||
dict: PyObjectRef,
|
||||
},
|
||||
None,
|
||||
NotImplemented,
|
||||
Class {
|
||||
name: String,
|
||||
dict: RefCell<PyAttributes>,
|
||||
@@ -1002,6 +1013,7 @@ impl fmt::Debug for PyObjectPayload {
|
||||
PyObjectPayload::Module { .. } => write!(f, "module"),
|
||||
PyObjectPayload::Scope { .. } => write!(f, "scope"),
|
||||
PyObjectPayload::None => write!(f, "None"),
|
||||
PyObjectPayload::NotImplemented => write!(f, "NotImplemented"),
|
||||
PyObjectPayload::Class { ref name, .. } => write!(f, "class {:?}", name),
|
||||
PyObjectPayload::Instance { .. } => write!(f, "instance"),
|
||||
PyObjectPayload::RustFunction { .. } => write!(f, "rust function"),
|
||||
@@ -1058,6 +1070,7 @@ impl PyObject {
|
||||
),
|
||||
PyObjectPayload::WeakRef { .. } => String::from("weakref"),
|
||||
PyObjectPayload::None => String::from("None"),
|
||||
PyObjectPayload::NotImplemented => String::from("NotImplemented"),
|
||||
PyObjectPayload::Class {
|
||||
ref name,
|
||||
dict: ref _dict,
|
||||
|
||||
Reference in New Issue
Block a user