Skip to content

Commit 62b0cf0

Browse files
youknowoneSnowapril
authored andcommitted
change TryIntoRef return type from PyResult<PyRef> to PyRef
1 parent 44f90a9 commit 62b0cf0

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

vm/src/builtins/pystr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,22 @@ impl fmt::Display for PyStr {
171171

172172
impl TryIntoRef<PyStr> for AsciiString {
173173
#[inline]
174-
fn try_into_ref(self, vm: &VirtualMachine) -> PyResult<PyRef<PyStr>> {
175-
Ok(unsafe { PyStr::new_ascii_unchecked(self.into()) }.into_ref(vm))
174+
fn try_into_ref(self, vm: &VirtualMachine) -> PyRef<PyStr> {
175+
unsafe { PyStr::new_ascii_unchecked(self.into()) }.into_ref(vm)
176176
}
177177
}
178178

179179
impl TryIntoRef<PyStr> for String {
180180
#[inline]
181-
fn try_into_ref(self, vm: &VirtualMachine) -> PyResult<PyRef<PyStr>> {
182-
Ok(PyStr::from(self).into_ref(vm))
181+
fn try_into_ref(self, vm: &VirtualMachine) -> PyRef<PyStr> {
182+
PyStr::from(self).into_ref(vm)
183183
}
184184
}
185185

186186
impl TryIntoRef<PyStr> for &str {
187187
#[inline]
188-
fn try_into_ref(self, vm: &VirtualMachine) -> PyResult<PyRef<PyStr>> {
189-
Ok(PyStr::from(self).into_ref(vm))
188+
fn try_into_ref(self, vm: &VirtualMachine) -> PyRef<PyStr> {
189+
PyStr::from(self).into_ref(vm)
190190
}
191191
}
192192

vm/src/pyobject.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ impl<T: PyValue> IntoPyObject for PyRefExact<T> {
408408
}
409409
}
410410
impl<T: PyValue> TryIntoRef<T> for PyRefExact<T> {
411-
fn try_into_ref(self, _vm: &VirtualMachine) -> PyResult<PyRef<T>> {
412-
Ok(self.obj)
411+
fn try_into_ref(self, _vm: &VirtualMachine) -> PyRef<T> {
412+
self.obj
413413
}
414414
}
415415

@@ -616,13 +616,13 @@ impl<T: TryFromObject> TryFromObject for Option<T> {
616616
/// Allows coercion of a types into PyRefs, so that we can write functions that can take
617617
/// refs, pyobject refs or basic types.
618618
pub trait TryIntoRef<T: PyObjectPayload> {
619-
fn try_into_ref(self, vm: &VirtualMachine) -> PyResult<PyRef<T>>;
619+
fn try_into_ref(self, vm: &VirtualMachine) -> PyRef<T>;
620620
}
621621

622622
impl<T: PyObjectPayload> TryIntoRef<T> for PyRef<T> {
623623
#[inline]
624-
fn try_into_ref(self, _vm: &VirtualMachine) -> PyResult<PyRef<T>> {
625-
Ok(self)
624+
fn try_into_ref(self, _vm: &VirtualMachine) -> PyRef<T> {
625+
self
626626
}
627627
}
628628

vm/src/vm.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ impl VirtualMachine {
807807
) -> PyBaseExceptionRef {
808808
let import_error = self.ctx.exceptions.import_error.clone();
809809
let exc = self.new_exception_msg(import_error, msg);
810-
self.set_attr(exc.as_object(), "name", name.try_into_ref(self).unwrap())
810+
self.set_attr(exc.as_object(), "name", name.try_into_ref(self))
811811
.unwrap();
812812
exc
813813
}
@@ -942,7 +942,7 @@ impl VirtualMachine {
942942
from_list: Option<PyTupleTyped<PyStrRef>>,
943943
level: usize,
944944
) -> PyResult {
945-
self._import_inner(module.try_into_ref(self)?, from_list, level)
945+
self._import_inner(module.try_into_ref(self), from_list, level)
946946
}
947947

948948
fn _import_inner(
@@ -1401,7 +1401,7 @@ impl VirtualMachine {
14011401
where
14021402
T: TryIntoRef<PyStr>,
14031403
{
1404-
let attr_name = attr_name.try_into_ref(self)?;
1404+
let attr_name = attr_name.try_into_ref(self);
14051405
vm_trace!("vm.__getattribute__: {:?} {:?}", obj, attr_name);
14061406
let getattro = obj
14071407
.class()
@@ -1454,12 +1454,12 @@ impl VirtualMachine {
14541454
K: TryIntoRef<PyStr>,
14551455
V: Into<PyObjectRef>,
14561456
{
1457-
let attr_name = attr_name.try_into_ref(self)?;
1457+
let attr_name = attr_name.try_into_ref(self);
14581458
self.call_set_attr(obj, attr_name, Some(attr_value.into()))
14591459
}
14601460

14611461
pub fn del_attr(&self, obj: &PyObjectRef, attr_name: impl TryIntoRef<PyStr>) -> PyResult<()> {
1462-
let attr_name = attr_name.try_into_ref(self)?;
1462+
let attr_name = attr_name.try_into_ref(self);
14631463
self.call_set_attr(obj, attr_name, None)
14641464
}
14651465

@@ -2173,7 +2173,7 @@ impl VirtualMachine {
21732173
attr_value: impl Into<PyObjectRef>,
21742174
) -> PyResult<()> {
21752175
let val = attr_value.into();
2176-
object::setattr(module, attr_name.try_into_ref(self)?, Some(val), self)
2176+
object::setattr(module, attr_name.try_into_ref(self), Some(val), self)
21772177
}
21782178
}
21792179

0 commit comments

Comments
 (0)