Skip to content

Commit c9816c3

Browse files
committed
Fix append snippet
1 parent 919b7f6 commit c9816c3

File tree

5 files changed

+24
-25
lines changed

5 files changed

+24
-25
lines changed

tests/Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ pytest = "*"
1010
[dev-packages]
1111

1212
[requires]
13-
python_version = "3.6"
13+
python_version = "3"

tests/Pipfile.lock

Lines changed: 14 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vm/src/objlist.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@ fn reverse(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
5656
}
5757
}
5858

59-
pub fn create_type(type_type: PyObjectRef) -> PyObjectRef {
59+
pub fn create_type(type_type: PyObjectRef, method_type: PyObjectRef) -> PyObjectRef {
6060
let mut dict = HashMap::new();
6161
dict.insert(
6262
"append".to_string(),
6363
PyObject::new(
6464
PyObjectKind::RustFunction { function: append },
65-
type_type.clone(),
65+
method_type.clone(),
6666
),
6767
);
6868
dict.insert(
6969
"reverse".to_string(),
7070
PyObject::new(
7171
PyObjectKind::RustFunction { function: reverse },
72-
type_type.clone(),
72+
method_type.clone(),
7373
),
7474
);
7575
let typ = PyObject::new(

vm/src/pyobject.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,17 @@ pub struct Scope {
6666
impl PyContext {
6767
pub fn new() -> PyContext {
6868
let type_type = objtype::create_type();
69+
let function_type = objfunction::create_type(type_type.clone());
70+
let bound_method_type = objfunction::create_bound_method_type(type_type.clone());
6971

7072
PyContext {
7173
int_type: objint::create_type(type_type.clone()),
72-
list_type: objlist::create_type(type_type.clone()),
74+
list_type: objlist::create_type(type_type.clone(), function_type.clone()),
7375
tuple_type: type_type.clone(),
7476
dict_type: type_type.clone(),
7577
none: PyObject::new(PyObjectKind::None, type_type.clone()),
76-
function_type: objfunction::create_type(type_type.clone()),
77-
bound_method_type: objfunction::create_bound_method_type(type_type.clone()),
78+
function_type: function_type,
79+
bound_method_type: bound_method_type,
7880
type_type: type_type,
7981
}
8082
}
@@ -253,7 +255,6 @@ impl AttributeProtocol for PyObjectRef {
253255
PyObjectKind::Module { name: _, ref dict } => dict.get_item(attr_name),
254256
PyObjectKind::Class { name: _, ref dict } => dict.get_item(attr_name),
255257
PyObjectKind::Instance { ref dict } => dict.get_item(attr_name),
256-
PyObjectKind::List { elements: _ } => self.typ().get_attr(attr_name),
257258
ref kind => unimplemented!("load_attr unimplemented for: {:?}", kind),
258259
}
259260
}
@@ -264,8 +265,7 @@ impl AttributeProtocol for PyObjectRef {
264265
PyObjectKind::Module { name: _, ref dict } => dict.contains_key(attr_name),
265266
PyObjectKind::Class { name: _, ref dict } => dict.contains_key(attr_name),
266267
PyObjectKind::Instance { ref dict } => dict.contains_key(attr_name),
267-
PyObjectKind::List { elements: _ } => self.typ().has_attr(attr_name),
268-
ref kind => unimplemented!("load_attr unimplemented for: {:?}", kind),
268+
_ => false,
269269
}
270270
}
271271

0 commit comments

Comments
 (0)