@@ -7,8 +7,8 @@ use crate::{
7
7
builtins:: { PyList , PySlice } ,
8
8
common:: static_cell,
9
9
function:: IntoPyObject ,
10
- IdProtocol , PyArithmeticValue , PyObjectRef , PyResult , PyValue , TryFromObject , TypeProtocol ,
11
- VirtualMachine ,
10
+ IdProtocol , PyArithmeticValue , PyObject , PyObjectRef , PyResult , PyValue , TryFromObject ,
11
+ TypeProtocol , VirtualMachine ,
12
12
} ;
13
13
14
14
// Sequence Protocol
@@ -17,15 +17,15 @@ use crate::{
17
17
#[ allow( clippy:: type_complexity) ]
18
18
#[ derive( Default , Clone ) ]
19
19
pub struct PySequenceMethods {
20
- pub length : Option < fn ( & PyObjectRef , & VirtualMachine ) -> PyResult < usize > > ,
21
- pub concat : Option < fn ( & PyObjectRef , & PyObjectRef , & VirtualMachine ) -> PyResult > ,
22
- pub repeat : Option < fn ( & PyObjectRef , usize , & VirtualMachine ) -> PyResult > ,
23
- pub item : Option < fn ( & PyObjectRef , isize , & VirtualMachine ) -> PyResult > ,
20
+ pub length : Option < fn ( & PyObject , & VirtualMachine ) -> PyResult < usize > > ,
21
+ pub concat : Option < fn ( & PyObject , & PyObject , & VirtualMachine ) -> PyResult > ,
22
+ pub repeat : Option < fn ( & PyObject , usize , & VirtualMachine ) -> PyResult > ,
23
+ pub item : Option < fn ( & PyObject , isize , & VirtualMachine ) -> PyResult > ,
24
24
pub ass_item :
25
- Option < fn ( & PyObjectRef , isize , Option < PyObjectRef > , & VirtualMachine ) -> PyResult < ( ) > > ,
26
- pub contains : Option < fn ( & PyObjectRef , & PyObjectRef , & VirtualMachine ) -> PyResult < bool > > ,
27
- pub inplace_concat : Option < fn ( & PyObjectRef , & PyObjectRef , & VirtualMachine ) -> PyResult > ,
28
- pub inplace_repeat : Option < fn ( & PyObjectRef , usize , & VirtualMachine ) -> PyResult > ,
25
+ Option < fn ( & PyObject , isize , Option < PyObjectRef > , & VirtualMachine ) -> PyResult < ( ) > > ,
26
+ pub contains : Option < fn ( & PyObject , & PyObject , & VirtualMachine ) -> PyResult < bool > > ,
27
+ pub inplace_concat : Option < fn ( & PyObject , & PyObject , & VirtualMachine ) -> PyResult > ,
28
+ pub inplace_repeat : Option < fn ( & PyObject , usize , & VirtualMachine ) -> PyResult > ,
29
29
}
30
30
31
31
impl PySequenceMethods {
@@ -59,7 +59,7 @@ pub struct PySequence {
59
59
}
60
60
61
61
impl PySequence {
62
- pub fn check ( obj : & PyObjectRef , vm : & VirtualMachine ) -> bool {
62
+ pub fn check ( obj : & PyObject , vm : & VirtualMachine ) -> bool {
63
63
let cls = obj. class ( ) ;
64
64
if cls. is ( & vm. ctx . types . dict_type ) {
65
65
return false ;
@@ -99,7 +99,7 @@ impl PySequence {
99
99
}
100
100
}
101
101
102
- pub fn concat ( & self , other : & PyObjectRef , vm : & VirtualMachine ) -> PyResult {
102
+ pub fn concat ( & self , other : & PyObject , vm : & VirtualMachine ) -> PyResult {
103
103
if let Some ( f) = self . methods ( ) . concat {
104
104
return f ( & self . obj , other, vm) ;
105
105
}
@@ -113,7 +113,7 @@ impl PySequence {
113
113
try_mul_for_repeat ( & self . obj , n, vm)
114
114
}
115
115
116
- pub fn inplace_concat ( & self , other : & PyObjectRef , vm : & VirtualMachine ) -> PyResult {
116
+ pub fn inplace_concat ( & self , other : & PyObject , vm : & VirtualMachine ) -> PyResult {
117
117
if let Some ( f) = self . methods ( ) . inplace_concat {
118
118
return f ( & self . obj , other, vm) ;
119
119
}
@@ -251,13 +251,13 @@ impl PySequence {
251
251
Ok ( list. into ( ) )
252
252
}
253
253
254
- pub fn contains ( & self , target : & PyObjectRef , vm : & VirtualMachine ) -> PyResult < bool > {
254
+ pub fn contains ( & self , target : & PyObject , vm : & VirtualMachine ) -> PyResult < bool > {
255
255
if let Some ( f) = self . methods ( ) . contains {
256
256
return f ( & self . obj , target, vm) ;
257
257
}
258
258
259
259
let iter = self . obj . clone ( ) . get_iter ( vm) ?;
260
- let iter = iter. iter ( vm) ?;
260
+ let iter = iter. iter :: < PyObjectRef > ( vm) ?;
261
261
262
262
for elem in iter {
263
263
let elem = elem?;
@@ -268,11 +268,11 @@ impl PySequence {
268
268
Ok ( false )
269
269
}
270
270
271
- pub fn count ( & self , target : & PyObjectRef , vm : & VirtualMachine ) -> PyResult < usize > {
271
+ pub fn count ( & self , target : & PyObject , vm : & VirtualMachine ) -> PyResult < usize > {
272
272
let mut n = 0 ;
273
273
274
274
let iter = self . obj . clone ( ) . get_iter ( vm) ?;
275
- let iter = iter. iter ( vm) ?;
275
+ let iter = iter. iter :: < PyObjectRef > ( vm) ?;
276
276
277
277
for elem in iter {
278
278
let elem = elem?;
@@ -287,11 +287,11 @@ impl PySequence {
287
287
Ok ( n)
288
288
}
289
289
290
- pub fn index ( & self , target : & PyObjectRef , vm : & VirtualMachine ) -> PyResult < usize > {
290
+ pub fn index ( & self , target : & PyObject , vm : & VirtualMachine ) -> PyResult < usize > {
291
291
let mut index: isize = -1 ;
292
292
293
293
let iter = self . obj . clone ( ) . get_iter ( vm) ?;
294
- let iter = iter. iter ( vm) ?;
294
+ let iter = iter. iter :: < PyObjectRef > ( vm) ?;
295
295
296
296
for elem in iter {
297
297
if index == isize:: MAX {
@@ -316,7 +316,7 @@ impl TryFromObject for PySequence {
316
316
}
317
317
}
318
318
319
- pub fn try_add_for_concat ( a : & PyObjectRef , b : & PyObjectRef , vm : & VirtualMachine ) -> PyResult {
319
+ pub fn try_add_for_concat ( a : & PyObject , b : & PyObject , vm : & VirtualMachine ) -> PyResult {
320
320
if PySequence :: check ( b, vm) {
321
321
let ret = vm. _add ( a, b) ?;
322
322
if let PyArithmeticValue :: Implemented ( ret) = PyArithmeticValue :: from_object ( vm, ret) {
@@ -329,19 +329,15 @@ pub fn try_add_for_concat(a: &PyObjectRef, b: &PyObjectRef, vm: &VirtualMachine)
329
329
) ) )
330
330
}
331
331
332
- pub fn try_mul_for_repeat ( a : & PyObjectRef , n : usize , vm : & VirtualMachine ) -> PyResult {
332
+ pub fn try_mul_for_repeat ( a : & PyObject , n : usize , vm : & VirtualMachine ) -> PyResult {
333
333
let ret = vm. _mul ( a, & n. into_pyobject ( vm) ) ?;
334
334
if let PyArithmeticValue :: Implemented ( ret) = PyArithmeticValue :: from_object ( vm, ret) {
335
335
return Ok ( ret) ;
336
336
}
337
337
Err ( vm. new_type_error ( format ! ( "'{}' object can't be repeated" , a. class( ) . name( ) ) ) )
338
338
}
339
339
340
- pub fn try_iadd_for_inplace_concat (
341
- a : & PyObjectRef ,
342
- b : & PyObjectRef ,
343
- vm : & VirtualMachine ,
344
- ) -> PyResult {
340
+ pub fn try_iadd_for_inplace_concat ( a : & PyObject , b : & PyObject , vm : & VirtualMachine ) -> PyResult {
345
341
if PySequence :: check ( b, vm) {
346
342
let ret = vm. _iadd ( a, b) ?;
347
343
if let PyArithmeticValue :: Implemented ( ret) = PyArithmeticValue :: from_object ( vm, ret) {
@@ -354,7 +350,7 @@ pub fn try_iadd_for_inplace_concat(
354
350
) ) )
355
351
}
356
352
357
- pub fn try_imul_for_inplace_repeat ( a : & PyObjectRef , n : usize , vm : & VirtualMachine ) -> PyResult {
353
+ pub fn try_imul_for_inplace_repeat ( a : & PyObject , n : usize , vm : & VirtualMachine ) -> PyResult {
358
354
let ret = vm. _imul ( a, & n. into_pyobject ( vm) ) ?;
359
355
if let PyArithmeticValue :: Implemented ( ret) = PyArithmeticValue :: from_object ( vm, ret) {
360
356
return Ok ( ret) ;
0 commit comments