@@ -5,6 +5,7 @@ use pyo3::exceptions::PyRuntimeError;
5
5
use pyo3:: prelude:: * ;
6
6
use pyo3:: types:: PyTuple ;
7
7
use pyo3:: { intern, Bound , PyObject , PyResult , Python } ;
8
+ use std:: borrow:: Borrow ;
8
9
use std:: cmp:: Reverse ;
9
10
use std:: collections:: hash_map:: Keys ;
10
11
use std:: collections:: HashSet ;
@@ -115,6 +116,26 @@ fn c3_boundary(py: Python, bases: &[PyTypeReference]) -> PyResult<usize> {
115
116
Ok ( boundary)
116
117
}
117
118
119
+ fn sub_c3_mro < I , G > (
120
+ py : Python ,
121
+ bases : I ,
122
+ abcs : & Vec < & PyTypeReference > ,
123
+ ) -> PyResult < Vec < Vec < PyTypeReference > > >
124
+ where
125
+ G : Borrow < PyTypeReference > ,
126
+ I : Iterator < Item = G > ,
127
+ {
128
+ let mut v: Vec < Vec < PyTypeReference > > = Vec :: new ( ) ;
129
+ for b in bases {
130
+ v. push ( c3_mro (
131
+ py,
132
+ b. borrow ( ) . wrapped ( ) . bind ( py) ,
133
+ abcs. iter ( ) . map ( |abc| abc. clone_ref ( py) ) . collect ( ) ,
134
+ ) ?) ;
135
+ }
136
+ Ok ( v)
137
+ }
138
+
118
139
fn c3_mro (
119
140
py : Python ,
120
141
cls : & Bound < ' _ , PyAny > ,
@@ -161,34 +182,13 @@ fn c3_mro(
161
182
let mut cls_ref = vec ! [ PyTypeReference :: new( cls. clone( ) . unbind( ) ) ] ;
162
183
mros. push ( & mut cls_ref) ;
163
184
164
- let mut explicit_bases_mro = Vec :: from_iter ( explicit_bases. iter ( ) . map ( |b| {
165
- c3_mro (
166
- py,
167
- b. wrapped ( ) . bind ( py) ,
168
- new_abcs. iter ( ) . map ( |abc| abc. clone_ref ( py) ) . collect ( ) ,
169
- )
170
- . unwrap ( )
171
- } ) ) ;
185
+ let mut explicit_bases_mro = sub_c3_mro ( py, explicit_bases. iter ( ) , & new_abcs) ?;
172
186
mros. extend ( & mut explicit_bases_mro) ;
173
187
174
- let mut abstract_bases_mro = Vec :: from_iter ( abstract_bases. iter ( ) . map ( |b| {
175
- c3_mro (
176
- py,
177
- b. wrapped ( ) . bind ( py) ,
178
- new_abcs. iter ( ) . map ( |abc| abc. clone_ref ( py) ) . collect ( ) ,
179
- )
180
- . unwrap ( )
181
- } ) ) ;
188
+ let mut abstract_bases_mro = sub_c3_mro ( py, abstract_bases. iter ( ) . map ( |v| * v) , & new_abcs) ?;
182
189
mros. extend ( & mut abstract_bases_mro) ;
183
190
184
- let mut other_bases_mro = Vec :: from_iter ( other_bases. iter ( ) . map ( |b| {
185
- c3_mro (
186
- py,
187
- b. wrapped ( ) . bind ( py) ,
188
- new_abcs. iter ( ) . map ( |abc| abc. clone_ref ( py) ) . collect ( ) ,
189
- )
190
- . unwrap ( )
191
- } ) ) ;
191
+ let mut other_bases_mro = sub_c3_mro ( py, other_bases. iter ( ) , & new_abcs) ?;
192
192
mros. extend ( & mut other_bases_mro) ;
193
193
194
194
let mut explicit_bases_cloned = Vec :: from_iter ( explicit_bases. iter ( ) . map ( |b| b. clone_ref ( py) ) ) ;
0 commit comments