Skip to content

Commit 80b0c25

Browse files
committed
change TryIntoRef return type from PyResult<PyRef> to PyRef
1 parent 4b12f11 commit 80b0c25

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
@@ -788,7 +788,7 @@ impl VirtualMachine {
788788
) -> PyBaseExceptionRef {
789789
let import_error = self.ctx.exceptions.import_error.clone();
790790
let exc = self.new_exception_msg(import_error, msg);
791-
self.set_attr(exc.as_object(), "name", name.try_into_ref(self).unwrap())
791+
self.set_attr(exc.as_object(), "name", name.try_into_ref(self))
792792
.unwrap();
793793
exc
794794
}
@@ -921,7 +921,7 @@ impl VirtualMachine {
921921
from_list: Option<PyTupleTyped<PyStrRef>>,
922922
level: usize,
923923
) -> PyResult {
924-
self._import_inner(module.try_into_ref(self)?, from_list, level)
924+
self._import_inner(module.try_into_ref(self), from_list, level)
925925
}
926926

927927
fn _import_inner(
@@ -1366,7 +1366,7 @@ impl VirtualMachine {
13661366
where
13671367
T: TryIntoRef<PyStr>,
13681368
{
1369-
let attr_name = attr_name.try_into_ref(self)?;
1369+
let attr_name = attr_name.try_into_ref(self);
13701370
vm_trace!("vm.__getattribute__: {:?} {:?}", obj, attr_name);
13711371
let getattro = obj
13721372
.class()
@@ -1419,12 +1419,12 @@ impl VirtualMachine {
14191419
K: TryIntoRef<PyStr>,
14201420
V: Into<PyObjectRef>,
14211421
{
1422-
let attr_name = attr_name.try_into_ref(self)?;
1422+
let attr_name = attr_name.try_into_ref(self);
14231423
self.call_set_attr(obj, attr_name, Some(attr_value.into()))
14241424
}
14251425

14261426
pub fn del_attr(&self, obj: &PyObjectRef, attr_name: impl TryIntoRef<PyStr>) -> PyResult<()> {
1427-
let attr_name = attr_name.try_into_ref(self)?;
1427+
let attr_name = attr_name.try_into_ref(self);
14281428
self.call_set_attr(obj, attr_name, None)
14291429
}
14301430

@@ -2138,7 +2138,7 @@ impl VirtualMachine {
21382138
attr_value: impl Into<PyObjectRef>,
21392139
) -> PyResult<()> {
21402140
let val = attr_value.into();
2141-
object::setattr(module, attr_name.try_into_ref(self)?, Some(val), self)
2141+
object::setattr(module, attr_name.try_into_ref(self), Some(val), self)
21422142
}
21432143
}
21442144

0 commit comments

Comments
 (0)