Skip to content

Commit 7364866

Browse files
authored
Merge pull request RustPython#477 from RustPython/dict7
Remove support for module get_item
2 parents 2d22a88 + 0c351ea commit 7364866

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

vm/src/import.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::error::Error;
66
use std::path::PathBuf;
77

88
use super::compile;
9-
use super::pyobject::{DictProtocol, PyResult};
9+
use super::pyobject::{AttributeProtocol, DictProtocol, PyResult};
1010
use super::util;
1111
use super::vm::VirtualMachine;
1212
use obj::{objsequence, objstr};
@@ -55,7 +55,7 @@ pub fn import_module(
5555
module_name: &str,
5656
) -> PyResult {
5757
// First, see if we already loaded the module:
58-
let sys_modules = vm.sys_module.get_item("modules").unwrap();
58+
let sys_modules = vm.sys_module.get_attr("modules").unwrap();
5959
if let Some(module) = sys_modules.get_item(module_name) {
6060
return Ok(module);
6161
}
@@ -74,7 +74,7 @@ pub fn import(
7474
// If we're importing a symbol, look it up and use it, otherwise construct a module and return
7575
// that
7676
if let Some(symbol) = symbol {
77-
module.get_item(symbol).map_or_else(
77+
module.get_attr(symbol).map_or_else(
7878
|| {
7979
let import_error = vm.context().exceptions.import_error.clone();
8080
Err(vm.new_exception(import_error, format!("cannot import name '{}'", symbol)))
@@ -87,7 +87,7 @@ pub fn import(
8787
}
8888

8989
fn find_source(vm: &VirtualMachine, current_path: PathBuf, name: &str) -> Result<PathBuf, String> {
90-
let sys_path = vm.sys_module.get_item("path").unwrap();
90+
let sys_path = vm.sys_module.get_attr("path").unwrap();
9191
let mut paths: Vec<PathBuf> = objsequence::get_elements(&sys_path)
9292
.iter()
9393
.map(|item| PathBuf::from(objstr::get_value(item)))

vm/src/pyobject.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,6 @@ impl DictProtocol for PyObjectRef {
829829
PyObjectPayload::Dict { ref elements } => {
830830
objdict::content_contains_key_str(elements, k)
831831
}
832-
PyObjectPayload::Module { ref dict, .. } => dict.contains_key(k),
833832
PyObjectPayload::Scope { ref scope } => scope.locals.contains_key(k),
834833
ref payload => unimplemented!("TODO {:?}", payload),
835834
}
@@ -838,7 +837,6 @@ impl DictProtocol for PyObjectRef {
838837
fn get_item(&self, k: &str) -> Option<PyObjectRef> {
839838
match self.borrow().payload {
840839
PyObjectPayload::Dict { ref elements } => objdict::content_get_key_str(elements, k),
841-
PyObjectPayload::Module { ref dict, .. } => dict.get_item(k),
842840
PyObjectPayload::Scope { ref scope } => scope.locals.get_item(k),
843841
_ => panic!("TODO"),
844842
}

0 commit comments

Comments
 (0)