Skip to content

Commit 4b12f11

Browse files
committed
Remove TryIntoRef for PyObjectRef
1 parent df866f9 commit 4b12f11

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

vm/src/builtins/weakproxy.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ impl SlotConstructor for PyWeakProxy {
4747
impl PyWeakProxy {
4848
// TODO: callbacks
4949
#[pymethod(magic)]
50-
fn getattr(&self, attr_name: PyObjectRef, vm: &VirtualMachine) -> PyResult {
51-
match self.weak.upgrade() {
52-
Some(obj) => vm.get_attribute(obj, attr_name),
53-
None => Err(vm.new_exception_msg(
50+
fn getattr(&self, attr_name: PyStrRef, vm: &VirtualMachine) -> PyResult {
51+
let obj = self.weak.upgrade().ok_or_else(|| {
52+
vm.new_exception_msg(
5453
vm.ctx.exceptions.reference_error.clone(),
5554
"weakly-referenced object no longer exists".to_owned(),
56-
)),
57-
}
55+
)
56+
})?;
57+
vm.get_attribute(obj, attr_name)
5858
}
5959
}
6060

vm/src/pyobject.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -626,15 +626,6 @@ impl<T: PyObjectPayload> TryIntoRef<T> for PyRef<T> {
626626
}
627627
}
628628

629-
impl<T> TryIntoRef<T> for PyObjectRef
630-
where
631-
T: PyValue,
632-
{
633-
fn try_into_ref(self, vm: &VirtualMachine) -> PyResult<PyRef<T>> {
634-
TryFromObject::try_from_object(vm, self)
635-
}
636-
}
637-
638629
/// Implemented by any type that can be created from a Python object.
639630
///
640631
/// Any type that implements `TryFromObject` is automatically `FromArgs`, and

vm/src/stdlib/errno.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
77
"errorcode" => errorcode.clone(),
88
});
99
for (name, code) in ERROR_CODES {
10-
let name = vm.new_pyobj(*name);
10+
let name = vm.ctx.new_str(*name);
1111
let code = vm.new_pyobj(*code);
12-
errorcode.set_item(code.clone(), name.clone(), vm).unwrap();
12+
errorcode
13+
.set_item(code.clone(), name.clone().into(), vm)
14+
.unwrap();
1315
vm.set_attr(&module, name, code).unwrap();
1416
}
1517
module

0 commit comments

Comments
 (0)