2
2
3
3
use crate :: ffi:: { self , Py_ssize_t } ;
4
4
use crate :: {
5
- exceptions, AsPyPointer , AsPyRef , FromPy , FromPyObject , IntoPy , IntoPyPointer , Py , PyAny ,
6
- PyErr , PyNativeType , PyObject , PyResult , PyTryFrom , Python , ToPyObject ,
5
+ exceptions, AsPyPointer , FromPy , FromPyObject , IntoPy , IntoPyPointer , Py , PyAny , PyErr ,
6
+ PyNativeType , PyObject , PyResult , PyTryFrom , Python , ToPyObject ,
7
7
} ;
8
8
use std:: slice;
9
9
@@ -77,20 +77,19 @@ impl PyTuple {
77
77
}
78
78
79
79
/// Returns `self` as a slice of objects.
80
- pub fn as_slice ( & self ) -> & [ PyObject ] {
81
- // This is safe because PyObject has the same memory layout as *mut ffi::PyObject,
80
+ pub fn as_slice ( & self ) -> & [ & PyAny ] {
81
+ // This is safe because &PyAny has the same memory layout as *mut ffi::PyObject,
82
82
// and because tuples are immutable.
83
83
unsafe {
84
84
let ptr = self . as_ptr ( ) as * mut ffi:: PyTupleObject ;
85
85
let slice = slice:: from_raw_parts ( ( * ptr) . ob_item . as_ptr ( ) , self . len ( ) ) ;
86
- & * ( slice as * const [ * mut ffi:: PyObject ] as * const [ PyObject ] )
86
+ & * ( slice as * const [ * mut ffi:: PyObject ] as * const [ & PyAny ] )
87
87
}
88
88
}
89
89
90
90
/// Returns an iterator over the tuple items.
91
91
pub fn iter ( & self ) -> PyTupleIterator {
92
92
PyTupleIterator {
93
- py : self . py ( ) ,
94
93
slice : self . as_slice ( ) ,
95
94
index : 0 ,
96
95
}
@@ -99,8 +98,7 @@ impl PyTuple {
99
98
100
99
/// Used by `PyTuple::iter()`.
101
100
pub struct PyTupleIterator < ' a > {
102
- py : Python < ' a > ,
103
- slice : & ' a [ PyObject ] ,
101
+ slice : & ' a [ & ' a PyAny ] ,
104
102
index : usize ,
105
103
}
106
104
@@ -110,7 +108,7 @@ impl<'a> Iterator for PyTupleIterator<'a> {
110
108
#[ inline]
111
109
fn next ( & mut self ) -> Option < & ' a PyAny > {
112
110
if self . index < self . slice . len ( ) {
113
- let item = self . slice [ self . index ] . as_ref ( self . py ) ;
111
+ let item = self . slice [ self . index ] ;
114
112
self . index += 1 ;
115
113
Some ( item)
116
114
} else {
@@ -180,7 +178,7 @@ macro_rules! tuple_conversion ({$length:expr,$(($refN:ident, $n:tt, $T:ident)),+
180
178
let slice = t. as_slice( ) ;
181
179
if t. len( ) == $length {
182
180
Ok ( (
183
- $( slice[ $n] . extract:: <$T>( obj . py ( ) ) ?, ) +
181
+ $( slice[ $n] . extract:: <$T>( ) ?, ) +
184
182
) )
185
183
} else {
186
184
Err ( wrong_tuple_length( t, $length) )
0 commit comments