Skip to content

Commit 6e7ed6b

Browse files
committed
Remove unwrap
1 parent 299da6d commit 6e7ed6b

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/singledispatch/builtins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl Builtins {
3939
) -> PyResult<bool> {
4040
let args = PyTuple::new(py, [cls, typ]);
4141
match self.issubclass_func.call1(py, args?) {
42-
Ok(result) => Ok(result.downcast_bound::<PyBool>(py).unwrap().is_true()),
42+
Ok(result) => Ok(result.downcast_bound::<PyBool>(py)?.is_true()),
4343
Err(e) => Err(e),
4444
}
4545
}

src/singledispatch/core.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn valid_dispatch_types(py: Python, cls: &Bound<'_, PyAny>) -> PyResult<Vec<Py<P
2929
} else {
3030
let typing_module = TypingModule::cached(py);
3131
if let Ok(origin) = typing_module.get_origin(py, cls) {
32-
if typing_module.is_union_type(py, origin.bind(py)) {
32+
if typing_module.is_union_type(py, origin.bind(py))? {
3333
if let Ok(type_args) = typing_module.get_args(py, cls) {
3434
let py_tuple = type_args.bind(py);
3535
let mut dispatch_types = Vec::with_capacity(py_tuple.len());
@@ -74,7 +74,7 @@ struct SingleDispatchState {
7474

7575
impl SingleDispatchState {
7676
fn find_impl(&mut self, py: Python, cls: Bound<'_, PyAny>) -> PyResult<PyObject> {
77-
let cls_mro = get_obj_mro(&cls.clone()).unwrap();
77+
let cls_mro = get_obj_mro(&cls.clone())?;
7878
let mro = match compose_mro(py, cls.clone(), self.registry.keys()) {
7979
Ok(mro) => mro,
8080
Err(e) => return Err(e),
@@ -166,7 +166,7 @@ impl SingleDispatch {
166166
match self.lock.lock() {
167167
Ok(mut state) => {
168168
let unbound_func = func.unbind();
169-
if typing_module.is_union_type(py, &cls) {
169+
if typing_module.is_union_type(py, &cls)? {
170170
match typing_module.get_args(py, &cls) {
171171
Ok(tuple) => {
172172
for tp in tuple.bind(py).iter() {

src/singledispatch/typing.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ impl TypingModule {
7676
self.get_origin.call1(py, PyTuple::new(py, [cls])?)
7777
}
7878

79-
pub fn is_union_type(&self, py: Python, cls: &Bound<'_, PyAny>) -> bool {
80-
let origin_type_reference = PyTypeReference::new(cls.into_py_any(py).unwrap());
81-
self.union_types.contains(&origin_type_reference)
79+
pub fn is_union_type(&self, py: Python, cls: &Bound<'_, PyAny>) -> PyResult<bool> {
80+
let origin_type_reference = PyTypeReference::new(cls.into_py_any(py)?);
81+
Ok(self.union_types.contains(&origin_type_reference))
8282
}
8383
}

0 commit comments

Comments
 (0)