mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Remove TryIntoRef for PyObjectRef
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user