@@ -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 ;
@@ -118,6 +119,26 @@ fn c3_boundary(py: Python, bases: &[PyTypeReference]) -> PyResult<usize> {
118
119
Ok ( boundary)
119
120
}
120
121
122
+ fn sub_c3_mro < I , G > (
123
+ py : Python ,
124
+ bases : I ,
125
+ abcs : & Vec < & PyTypeReference > ,
126
+ ) -> PyResult < Vec < Vec < PyTypeReference > > >
127
+ where
128
+ G : Borrow < PyTypeReference > ,
129
+ I : Iterator < Item = G > ,
130
+ {
131
+ let mut v: Vec < Vec < PyTypeReference > > = Vec :: new ( ) ;
132
+ for b in bases {
133
+ v. push ( c3_mro (
134
+ py,
135
+ b. borrow ( ) . wrapped ( ) . bind ( py) ,
136
+ abcs. iter ( ) . map ( |abc| abc. clone_ref ( py) ) . collect ( ) ,
137
+ ) ?) ;
138
+ }
139
+ Ok ( v)
140
+ }
141
+
121
142
fn c3_mro (
122
143
py : Python ,
123
144
cls : & Bound < ' _ , PyAny > ,
@@ -164,34 +185,13 @@ fn c3_mro(
164
185
let mut cls_ref = vec ! [ PyTypeReference :: new( cls. clone( ) . unbind( ) ) ] ;
165
186
mros. push ( & mut cls_ref) ;
166
187
167
- let mut explicit_bases_mro = Vec :: from_iter ( explicit_bases. iter ( ) . map ( |b| {
168
- c3_mro (
169
- py,
170
- b. wrapped ( ) . bind ( py) ,
171
- new_abcs. iter ( ) . map ( |abc| abc. clone_ref ( py) ) . collect ( ) ,
172
- )
173
- . unwrap ( )
174
- } ) ) ;
188
+ let mut explicit_bases_mro = sub_c3_mro ( py, explicit_bases. iter ( ) , & new_abcs) ?;
175
189
mros. extend ( & mut explicit_bases_mro) ;
176
190
177
- let mut abstract_bases_mro = Vec :: from_iter ( abstract_bases. iter ( ) . map ( |b| {
178
- c3_mro (
179
- py,
180
- b. wrapped ( ) . bind ( py) ,
181
- new_abcs. iter ( ) . map ( |abc| abc. clone_ref ( py) ) . collect ( ) ,
182
- )
183
- . unwrap ( )
184
- } ) ) ;
191
+ let mut abstract_bases_mro = sub_c3_mro ( py, abstract_bases. iter ( ) . map ( |v| * v) , & new_abcs) ?;
185
192
mros. extend ( & mut abstract_bases_mro) ;
186
193
187
- let mut other_bases_mro = Vec :: from_iter ( other_bases. iter ( ) . map ( |b| {
188
- c3_mro (
189
- py,
190
- b. wrapped ( ) . bind ( py) ,
191
- new_abcs. iter ( ) . map ( |abc| abc. clone_ref ( py) ) . collect ( ) ,
192
- )
193
- . unwrap ( )
194
- } ) ) ;
194
+ let mut other_bases_mro = sub_c3_mro ( py, other_bases. iter ( ) , & new_abcs) ?;
195
195
mros. extend ( & mut other_bases_mro) ;
196
196
197
197
let mut explicit_bases_cloned = Vec :: from_iter ( explicit_bases. iter ( ) . map ( |b| b. clone_ref ( py) ) ) ;
0 commit comments