@@ -14,13 +14,10 @@ use pyo3::{
14
14
use std:: collections:: HashMap ;
15
15
use std:: sync:: Mutex ;
16
16
17
- fn get_abc_cache_token ( py : Python ) -> Bound < ' _ , PyAny > {
18
- py. import ( intern ! ( py, "abc" ) )
19
- . unwrap ( )
20
- . getattr ( intern ! ( py, "get_cache_token" ) )
21
- . unwrap ( )
17
+ fn get_abc_cache_token ( py : Python ) -> PyResult < Bound < ' _ , PyAny > > {
18
+ py. import ( intern ! ( py, "abc" ) ) ?
19
+ . getattr ( intern ! ( py, "get_cache_token" ) ) ?
22
20
. call0 ( )
23
- . unwrap ( )
24
21
}
25
22
26
23
fn valid_dispatch_types ( py : Python , cls : & Bound < ' _ , PyAny > ) -> PyResult < Vec < Py < PyType > > > {
@@ -83,26 +80,29 @@ impl SingleDispatchState {
83
80
mro_match = Some ( typ. clone_ref ( py) ) ;
84
81
}
85
82
86
- if mro_match. is_some ( ) {
87
- let m = & mro_match. unwrap ( ) . clone_ref ( py) ;
88
- if self . registry . contains_key ( typ)
89
- && !cls_mro. contains ( typ)
90
- && !cls_mro. contains ( m)
91
- && Builtins :: cached ( py)
83
+ match mro_match {
84
+ Some ( m) => {
85
+ let m = & m. clone_ref ( py) ;
86
+ if self . registry . contains_key ( typ)
87
+ && !cls_mro. contains ( typ)
88
+ && !cls_mro. contains ( m)
89
+ && Builtins :: cached ( py)
92
90
. issubclass ( py, m. wrapped ( ) . bind ( py) , typ. wrapped ( ) . bind ( py) )
93
91
. is_ok_and ( |res| res)
94
- {
95
- return Err ( PyRuntimeError :: new_err ( format ! (
96
- "Ambiguous dispatch: {m} or {typ}"
97
- ) ) ) ;
92
+ {
93
+ return Err ( PyRuntimeError :: new_err ( format ! (
94
+ "Ambiguous dispatch: {m} or {typ}"
95
+ ) ) ) ;
96
+ }
97
+ mro_match = Some ( m. clone_ref ( py) ) ;
98
+ eprintln ! ( "MRO match: {m}" ) ;
99
+ break ;
98
100
}
99
- mro_match = Some ( m. clone_ref ( py) ) ;
100
- eprintln ! ( "MRO match: {m}" ) ;
101
- break ;
101
+ _ => { } ,
102
102
}
103
103
}
104
104
let impl_fn = match mro_match {
105
- Some ( _ ) => match self . registry . get ( & mro_match . unwrap ( ) ) {
105
+ Some ( v ) => match self . registry . get ( & v ) {
106
106
Some ( & ref it) => Some ( it. clone_ref ( py) ) ,
107
107
None => None ,
108
108
} ,
@@ -180,7 +180,7 @@ impl SingleDispatch {
180
180
}
181
181
if state. cache_token . is_none ( ) {
182
182
if let Ok ( _) = unbound_func. getattr ( py, intern ! ( py, "__abstractmethods__" ) ) {
183
- state. cache_token = Some ( get_abc_cache_token ( py) . unbind ( ) ) ;
183
+ state. cache_token = Some ( get_abc_cache_token ( py) ? . unbind ( ) ) ;
184
184
}
185
185
}
186
186
state. cache . clear ( ) ;
@@ -253,7 +253,7 @@ impl SingleDispatch {
253
253
Ok ( mut state) => {
254
254
match & state. cache_token {
255
255
Some ( cache_token) => {
256
- let current_token = get_abc_cache_token ( py) ;
256
+ let current_token = get_abc_cache_token ( py) ? ;
257
257
match current_token. rich_compare ( cache_token. bind ( py) , CompareOp :: Eq ) {
258
258
Ok ( _) => {
259
259
state. cache . clear ( ) ;
0 commit comments