@@ -108,10 +108,10 @@ impl LookupKey {
108
108
}
109
109
}
110
110
111
- pub fn py_get_dict_item < ' data , ' s > (
111
+ pub fn py_get_dict_item < ' py , ' s > (
112
112
& ' s self ,
113
- dict : & ' data PyDict ,
114
- ) -> ValResult < Option < ( & ' s LookupPath , & ' data PyAny ) > > {
113
+ dict : & Py2 < ' py , PyDict > ,
114
+ ) -> ValResult < Option < ( & ' s LookupPath , Py2 < ' py , PyAny > ) > > {
115
115
match self {
116
116
Self :: Simple { py_key, path, .. } => match dict. get_item ( py_key) ? {
117
117
Some ( value) => Ok ( Some ( ( path, value) ) ) ,
@@ -134,7 +134,7 @@ impl LookupKey {
134
134
for path in path_choices {
135
135
// iterate over the path and plug each value into the py_any from the last step, starting with dict
136
136
// this could just be a loop but should be somewhat faster with a functional design
137
- if let Some ( v) = path. iter ( ) . try_fold ( dict as & PyAny , |d, loc| loc. py_get_item ( d) ) {
137
+ if let Some ( v) = path. iter ( ) . try_fold ( ( * * dict) . clone ( ) , |d, loc| loc. py_get_item ( & d) ) {
138
138
// Successfully found an item, return it
139
139
return Ok ( Some ( ( path, v) ) ) ;
140
140
}
@@ -145,22 +145,22 @@ impl LookupKey {
145
145
}
146
146
}
147
147
148
- pub fn py_get_string_mapping_item < ' data , ' s > (
148
+ pub fn py_get_string_mapping_item < ' py , ' s > (
149
149
& ' s self ,
150
- dict : & ' data PyDict ,
151
- ) -> ValResult < Option < ( & ' s LookupPath , StringMapping < ' data > ) > > {
150
+ dict : & Py2 < ' py , PyDict > ,
151
+ ) -> ValResult < Option < ( & ' s LookupPath , StringMapping < ' py > ) > > {
152
152
if let Some ( ( path, py_any) ) = self . py_get_dict_item ( dict) ? {
153
- let value = StringMapping :: new_value ( py_any) ?;
153
+ let value = StringMapping :: new_value ( py_any. into_gil_ref ( ) ) ?;
154
154
Ok ( Some ( ( path, value) ) )
155
155
} else {
156
156
Ok ( None )
157
157
}
158
158
}
159
159
160
- pub fn py_get_mapping_item < ' data , ' s > (
160
+ pub fn py_get_mapping_item < ' py , ' s > (
161
161
& ' s self ,
162
- dict : & ' data PyMapping ,
163
- ) -> ValResult < Option < ( & ' s LookupPath , & ' data PyAny ) > > {
162
+ dict : & Py2 < ' py , PyMapping > ,
163
+ ) -> ValResult < Option < ( & ' s LookupPath , Py2 < ' py , PyAny > ) > > {
164
164
match self {
165
165
Self :: Simple { py_key, path, .. } => match dict. get_item ( py_key) {
166
166
Ok ( value) => Ok ( Some ( ( path, value) ) ) ,
@@ -183,7 +183,7 @@ impl LookupKey {
183
183
for path in path_choices {
184
184
// iterate over the path and plug each value into the py_any from the last step, starting with dict
185
185
// this could just be a loop but should be somewhat faster with a functional design
186
- if let Some ( v) = path. iter ( ) . try_fold ( dict as & PyAny , |d, loc| loc. py_get_item ( d) ) {
186
+ if let Some ( v) = path. iter ( ) . try_fold ( ( * * dict) . clone ( ) , |d, loc| loc. py_get_item ( & d) ) {
187
187
// Successfully found an item, return it
188
188
return Ok ( Some ( ( path, v) ) ) ;
189
189
}
@@ -194,28 +194,28 @@ impl LookupKey {
194
194
}
195
195
}
196
196
197
- pub fn py_get_attr < ' data , ' s > (
197
+ pub fn py_get_attr < ' py , ' s > (
198
198
& ' s self ,
199
- obj : & ' data PyAny ,
200
- kwargs : Option < & ' data PyDict > ,
201
- ) -> ValResult < Option < ( & ' s LookupPath , & ' data PyAny ) > > {
199
+ obj : & Py2 < ' py , PyAny > ,
200
+ kwargs : Option < & Py2 < ' py , PyDict > > ,
201
+ ) -> ValResult < Option < ( & ' s LookupPath , Py2 < ' py , PyAny > ) > > {
202
202
match self . _py_get_attr ( obj, kwargs) {
203
203
Ok ( v) => Ok ( v) ,
204
204
Err ( err) => {
205
205
let error = py_err_string ( obj. py ( ) , err) ;
206
206
Err ( ValError :: new (
207
207
ErrorType :: GetAttributeError { error, context : None } ,
208
- obj,
208
+ obj. as_gil_ref ( ) ,
209
209
) )
210
210
}
211
211
}
212
212
}
213
213
214
- pub fn _py_get_attr < ' data , ' s > (
214
+ pub fn _py_get_attr < ' py , ' s > (
215
215
& ' s self ,
216
- obj : & ' data PyAny ,
217
- kwargs : Option < & ' data PyDict > ,
218
- ) -> PyResult < Option < ( & ' s LookupPath , & ' data PyAny ) > > {
216
+ obj : & Py2 < ' py , PyAny > ,
217
+ kwargs : Option < & Py2 < ' py , PyDict > > ,
218
+ ) -> PyResult < Option < ( & ' s LookupPath , Py2 < ' py , PyAny > ) > > {
219
219
if let Some ( dict) = kwargs {
220
220
if let Ok ( Some ( item) ) = self . py_get_dict_item ( dict) {
221
221
return Ok ( Some ( item) ) ;
@@ -244,9 +244,9 @@ impl LookupKey {
244
244
' outer: for path in path_choices {
245
245
// similar to above, but using `py_get_attrs`, we can't use try_fold because of the extra Err
246
246
// so we have to loop manually
247
- let mut v = obj;
247
+ let mut v = obj. clone ( ) ;
248
248
for loc in path. iter ( ) {
249
- v = match loc. py_get_attrs ( v) {
249
+ v = match loc. py_get_attrs ( & v) {
250
250
Ok ( Some ( v) ) => v,
251
251
Ok ( None ) => {
252
252
continue ' outer;
@@ -446,7 +446,7 @@ impl PathItem {
446
446
}
447
447
}
448
448
449
- pub fn py_get_item < ' a > ( & self , py_any : & ' a PyAny ) -> Option < & ' a PyAny > {
449
+ pub fn py_get_item < ' py > ( & self , py_any : & Py2 < ' py , PyAny > ) -> Option < Py2 < ' py , PyAny > > {
450
450
// we definitely don't want to index strings, so explicitly omit this case
451
451
if py_any. downcast :: < PyString > ( ) . is_ok ( ) {
452
452
None
@@ -463,7 +463,7 @@ impl PathItem {
463
463
}
464
464
}
465
465
466
- pub fn py_get_attrs < ' a > ( & self , obj : & ' a PyAny ) -> PyResult < Option < & ' a PyAny > > {
466
+ pub fn py_get_attrs < ' py > ( & self , obj : & Py2 < ' py , PyAny > ) -> PyResult < Option < Py2 < ' py , PyAny > > > {
467
467
match self {
468
468
Self :: S ( _, py_key) => {
469
469
// if obj is a dict, we want to use get_item, not getattr
@@ -506,7 +506,7 @@ impl PathItem {
506
506
507
507
/// wrapper around `getattr` that returns `Ok(None)` for attribute errors, but returns other errors
508
508
/// We don't check `try_from_attributes` because that check was performed on the top level object before we got here
509
- fn py_get_attrs < ' a > ( obj : & ' a PyAny , attr_name : & Py < PyString > ) -> PyResult < Option < & ' a PyAny > > {
509
+ fn py_get_attrs < ' py > ( obj : & Py2 < ' py , PyAny > , attr_name : & Py < PyString > ) -> PyResult < Option < Py2 < ' py , PyAny > > > {
510
510
match obj. getattr ( attr_name. extract :: < & PyString > ( obj. py ( ) ) ?) {
511
511
Ok ( attr) => Ok ( Some ( attr) ) ,
512
512
Err ( err) => {
0 commit comments