@@ -206,15 +206,15 @@ fn extract_value_single_or_list_for_type(
206
206
}
207
207
}
208
208
209
- fn object_to_py ( py : Python , obj : & [ ( String , Value ) ] ) -> PyResult < PyObject > {
209
+ fn object_to_py ( py : Python , obj : & [ ( String , Value ) ] ) -> PyResult < Py < PyAny > > {
210
210
let dict = PyDict :: new ( py) ;
211
211
for ( k, v) in obj. iter ( ) {
212
212
dict. set_item ( k, value_to_py ( py, v) ?) ?;
213
213
}
214
214
Ok ( dict. into ( ) )
215
215
}
216
216
217
- fn value_to_py ( py : Python , value : & Value ) -> PyResult < PyObject > {
217
+ fn value_to_py ( py : Python , value : & Value ) -> PyResult < Py < PyAny > > {
218
218
Ok ( match value {
219
219
Value :: Null => py. None ( ) ,
220
220
Value :: Str ( text) => text. into_py_any ( py) ?,
@@ -657,10 +657,10 @@ impl Document {
657
657
///
658
658
/// For this reason, the dictionary, will associate
659
659
/// a list of value for every field.
660
- fn to_dict ( & self , py : Python ) -> PyResult < PyObject > {
660
+ fn to_dict ( & self , py : Python ) -> PyResult < Py < PyAny > > {
661
661
let dict = PyDict :: new ( py) ;
662
662
for ( key, values) in & self . field_values {
663
- let values_py: Vec < PyObject > = values
663
+ let values_py: Vec < Py < PyAny > > = values
664
664
. iter ( )
665
665
. map ( |v| value_to_py ( py, v) )
666
666
. collect :: < PyResult < _ > > ( ) ?;
@@ -824,7 +824,7 @@ impl Document {
824
824
& self ,
825
825
py : Python ,
826
826
fieldname : & str ,
827
- ) -> PyResult < Option < PyObject > > {
827
+ ) -> PyResult < Option < Py < PyAny > > > {
828
828
if let Some ( value) = self . iter_values_for_field ( fieldname) . next ( ) {
829
829
let py_value = value_to_py ( py, value) ?;
830
830
Ok ( Some ( py_value) )
@@ -840,14 +840,18 @@ impl Document {
840
840
///
841
841
/// Returns a list of values.
842
842
/// The type of the value depends on the field.
843
- fn get_all ( & self , py : Python , field_name : & str ) -> PyResult < Vec < PyObject > > {
843
+ fn get_all (
844
+ & self ,
845
+ py : Python ,
846
+ field_name : & str ,
847
+ ) -> PyResult < Vec < Py < PyAny > > > {
844
848
self . iter_values_for_field ( field_name)
845
849
. map ( |value| value_to_py ( py, value) )
846
850
. collect :: < PyResult < Vec < _ > > > ( )
847
851
}
848
852
849
- fn __getitem__ ( & self , field_name : & str ) -> PyResult < Vec < PyObject > > {
850
- Python :: with_gil ( |py| -> PyResult < Vec < PyObject > > {
853
+ fn __getitem__ ( & self , field_name : & str ) -> PyResult < Vec < Py < PyAny > > > {
854
+ Python :: attach ( |py| -> PyResult < Vec < Py < PyAny > > > {
851
855
self . get_all ( py, field_name)
852
856
} )
853
857
}
@@ -869,7 +873,7 @@ impl Document {
869
873
other : & Self ,
870
874
op : CompareOp ,
871
875
py : Python < ' _ > ,
872
- ) -> PyResult < PyObject > {
876
+ ) -> PyResult < Py < PyAny > > {
873
877
match op {
874
878
CompareOp :: Eq => ( self == other) . into_py_any ( py) ,
875
879
CompareOp :: Ne => ( self != other) . into_py_any ( py) ,
0 commit comments