Skip to content

Use new_attribute_error in more places #657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions vm/src/obj/objfunction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,9 @@ fn classmethod_get(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
let py_method = vm.ctx.new_bound_method(function, py_obj);
Ok(py_method)
}
None => {
let attribute_error = vm.context().exceptions.attribute_error.clone();
Err(vm.new_exception(
attribute_error,
String::from("Attribute Error: classmethod must have 'function' attribute"),
))
}
None => Err(vm.new_attribute_error(
"Attribute Error: classmethod must have 'function' attribute".to_string(),
)),
}
}

Expand All @@ -162,13 +158,9 @@ fn staticmethod_get(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
);
match cls.get_attr("function") {
Some(function) => Ok(function),
None => {
let attribute_error = vm.context().exceptions.attribute_error.clone();
Err(vm.new_exception(
attribute_error,
String::from("Attribute Error: staticmethod must have 'function' attribute"),
))
}
None => Err(vm.new_attribute_error(
"Attribute Error: staticmethod must have 'function' attribute".to_string(),
)),
}
}

Expand Down
6 changes: 1 addition & 5 deletions vm/src/obj/objobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,7 @@ fn object_getattribute(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
} else if let Some(getter) = cls.get_attr("__getattr__") {
vm.invoke(getter, vec![cls, name_str.clone()])
} else {
let attribute_error = vm.context().exceptions.attribute_error.clone();
Err(vm.new_exception(
attribute_error,
format!("{} has no attribute '{}'", obj, name),
))
Err(vm.new_attribute_error(format!("{} has no attribute '{}'", obj, name)))
}
}

Expand Down
6 changes: 1 addition & 5 deletions vm/src/obj/objtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,7 @@ pub fn type_getattribute(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult
} else if let Some(getter) = cls.get_attr("__getattr__") {
vm.invoke(getter, vec![mcl, name_str.clone()])
} else {
let attribute_error = vm.context().exceptions.attribute_error.clone();
Err(vm.new_exception(
attribute_error,
format!("{} has no attribute '{}'", cls, name),
))
Err(vm.new_attribute_error(format!("{} has no attribute '{}'", cls, name)))
}
}

Expand Down
4 changes: 2 additions & 2 deletions vm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ impl VirtualMachine {
}

pub fn new_attribute_error(&mut self, msg: String) -> PyObjectRef {
let type_error = self.ctx.exceptions.attribute_error.clone();
self.new_exception(type_error, msg)
let attribute_error = self.ctx.exceptions.attribute_error.clone();
self.new_exception(attribute_error, msg)
}

pub fn new_type_error(&mut self, msg: String) -> PyObjectRef {
Expand Down