mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Remove unnecessary mutability in DictProtocol.
This commit is contained in:
@@ -11,7 +11,7 @@ use super::pyobject::{
|
||||
use super::vm::VirtualMachine;
|
||||
|
||||
fn get_locals(vm: &mut VirtualMachine) -> PyObjectRef {
|
||||
let mut d = vm.new_dict();
|
||||
let d = vm.new_dict();
|
||||
// TODO: implement dict_iter_items?
|
||||
let locals = vm.get_locals();
|
||||
match locals.borrow().kind {
|
||||
|
||||
@@ -270,8 +270,8 @@ impl AttributeProtocol for PyObjectRef {
|
||||
}
|
||||
|
||||
fn set_attr(&self, attr_name: &String, value: PyObjectRef) {
|
||||
match self.borrow_mut().kind {
|
||||
PyObjectKind::Instance { ref mut dict } => dict.set_item(attr_name, value),
|
||||
match self.borrow().kind {
|
||||
PyObjectKind::Instance { ref dict } => dict.set_item(attr_name, value),
|
||||
ref kind => unimplemented!("load_attr unimplemented for: {:?}", kind),
|
||||
};
|
||||
}
|
||||
@@ -280,7 +280,7 @@ impl AttributeProtocol for PyObjectRef {
|
||||
pub trait DictProtocol {
|
||||
fn contains_key(&self, k: &String) -> bool;
|
||||
fn get_item(&self, k: &String) -> PyObjectRef;
|
||||
fn set_item(&mut self, k: &String, v: PyObjectRef);
|
||||
fn set_item(&self, k: &String, v: PyObjectRef);
|
||||
}
|
||||
|
||||
impl DictProtocol for PyObjectRef {
|
||||
@@ -302,7 +302,7 @@ impl DictProtocol for PyObjectRef {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_item(&mut self, k: &String, v: PyObjectRef) {
|
||||
fn set_item(&self, k: &String, v: PyObjectRef) {
|
||||
match self.borrow_mut().kind {
|
||||
PyObjectKind::Dict {
|
||||
elements: ref mut el,
|
||||
|
||||
@@ -8,9 +8,9 @@ use super::pyobject::{DictProtocol, PyContext, PyObjectRef};
|
||||
|
||||
pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
|
||||
let path = ctx.new_list(None);
|
||||
let mut modules = ctx.new_dict();
|
||||
let modules = ctx.new_dict();
|
||||
let sys_name = "sys".to_string();
|
||||
let mut sys_mod = ctx.new_module(&sys_name, ctx.new_scope(None));
|
||||
let sys_mod = ctx.new_module(&sys_name, ctx.new_scope(None));
|
||||
modules.set_item(&sys_name, sys_mod.clone());
|
||||
sys_mod.set_item(&"modules".to_string(), modules);
|
||||
sys_mod.set_item(&"path".to_string(), path);
|
||||
|
||||
Reference in New Issue
Block a user