Remove TryIntoRef for PyObjectRef

This commit is contained in:
Jeong YunWon
2021-10-12 02:01:37 +09:00
parent df866f9b93
commit 4b12f11eb5
3 changed files with 10 additions and 17 deletions

View File

@@ -47,14 +47,14 @@ impl SlotConstructor for PyWeakProxy {
impl PyWeakProxy {
// TODO: callbacks
#[pymethod(magic)]
fn getattr(&self, attr_name: PyObjectRef, vm: &VirtualMachine) -> PyResult {
match self.weak.upgrade() {
Some(obj) => vm.get_attribute(obj, attr_name),
None => Err(vm.new_exception_msg(
fn getattr(&self, attr_name: PyStrRef, vm: &VirtualMachine) -> PyResult {
let obj = self.weak.upgrade().ok_or_else(|| {
vm.new_exception_msg(
vm.ctx.exceptions.reference_error.clone(),
"weakly-referenced object no longer exists".to_owned(),
)),
}
)
})?;
vm.get_attribute(obj, attr_name)
}
}

View File

@@ -626,15 +626,6 @@ impl<T: PyObjectPayload> TryIntoRef<T> for PyRef<T> {
}
}
impl<T> TryIntoRef<T> for PyObjectRef
where
T: PyValue,
{
fn try_into_ref(self, vm: &VirtualMachine) -> PyResult<PyRef<T>> {
TryFromObject::try_from_object(vm, self)
}
}
/// Implemented by any type that can be created from a Python object.
///
/// Any type that implements `TryFromObject` is automatically `FromArgs`, and

View File

@@ -7,9 +7,11 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
"errorcode" => errorcode.clone(),
});
for (name, code) in ERROR_CODES {
let name = vm.new_pyobj(*name);
let name = vm.ctx.new_str(*name);
let code = vm.new_pyobj(*code);
errorcode.set_item(code.clone(), name.clone(), vm).unwrap();
errorcode
.set_item(code.clone(), name.clone().into(), vm)
.unwrap();
vm.set_attr(&module, name, code).unwrap();
}
module