mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
16
tests/snippets/none.py
Normal file
16
tests/snippets/none.py
Normal file
@@ -0,0 +1,16 @@
|
||||
assert None is None
|
||||
|
||||
y = None
|
||||
x = None
|
||||
assert x is y
|
||||
|
||||
def none():
|
||||
pass
|
||||
|
||||
def none2():
|
||||
return None
|
||||
|
||||
assert none() is none()
|
||||
assert none() is x
|
||||
|
||||
assert none() is none2()
|
||||
@@ -7,7 +7,11 @@ use std::collections::HashMap;
|
||||
use super::pyobject::{PyObject, PyObjectKind, PyObjectRef};
|
||||
|
||||
pub fn create_type() -> PyObjectRef {
|
||||
let typ = PyObject::default().into_ref();
|
||||
let typ = PyObject {
|
||||
kind: PyObjectKind::None,
|
||||
typ: None,
|
||||
}.into_ref();
|
||||
|
||||
let dict = PyObject::new(
|
||||
PyObjectKind::Dict {
|
||||
elements: HashMap::new(),
|
||||
|
||||
@@ -42,6 +42,7 @@ impl fmt::Display for PyObjectRef {
|
||||
#[derive(Debug)]
|
||||
pub struct PyContext {
|
||||
pub type_type: PyObjectRef,
|
||||
pub none: PyObjectRef,
|
||||
pub int_type: PyObjectRef,
|
||||
pub list_type: PyObjectRef,
|
||||
pub tuple_type: PyObjectRef,
|
||||
@@ -70,6 +71,7 @@ impl PyContext {
|
||||
list_type: type_type.clone(),
|
||||
tuple_type: type_type.clone(),
|
||||
dict_type: type_type.clone(),
|
||||
none: PyObject::new(PyObjectKind::None, type_type.clone()),
|
||||
function_type: objfunction::create_type(type_type.clone()),
|
||||
bound_method_type: objfunction::create_bound_method_type(type_type.clone()),
|
||||
type_type: type_type,
|
||||
@@ -187,16 +189,6 @@ pub struct PyObject {
|
||||
// pub dict: HashMap<String, PyObjectRef>, // __dict__ member
|
||||
}
|
||||
|
||||
impl Default for PyObject {
|
||||
fn default() -> PyObject {
|
||||
PyObject {
|
||||
kind: PyObjectKind::None,
|
||||
typ: None,
|
||||
// dict: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait IdProtocol {
|
||||
fn get_id(&self) -> usize;
|
||||
}
|
||||
|
||||
@@ -65,8 +65,7 @@ impl VirtualMachine {
|
||||
}
|
||||
|
||||
pub fn get_none(&self) -> PyObjectRef {
|
||||
// TODO
|
||||
self.ctx.new_bool(false)
|
||||
self.ctx.none.clone()
|
||||
}
|
||||
|
||||
pub fn new_bound_method(&self, function: PyObjectRef, object: PyObjectRef) -> PyObjectRef {
|
||||
@@ -573,7 +572,7 @@ impl VirtualMachine {
|
||||
&bytecode::Constant::Code { ref code } => {
|
||||
PyObject::new(PyObjectKind::Code { code: code.clone() }, self.get_type())
|
||||
}
|
||||
&bytecode::Constant::None => PyObject::new(PyObjectKind::None, self.get_type()),
|
||||
&bytecode::Constant::None => self.ctx.none.clone(),
|
||||
};
|
||||
self.push_value(obj);
|
||||
None
|
||||
|
||||
Reference in New Issue
Block a user