File tree Expand file tree Collapse file tree 5 files changed +22
-26
lines changed Expand file tree Collapse file tree 5 files changed +22
-26
lines changed Original file line number Diff line number Diff line change 12
12
13
13
class CommonTest (seq_tests .CommonTest ):
14
14
15
- # TODO: RUSTPYTHON
16
- @unittest .expectedFailure
17
15
def test_init (self ):
18
16
# Iterable arg is optional
19
17
self .assertEqual (self .type2test ([]), self .type2test ())
Original file line number Diff line number Diff line change @@ -47,8 +47,6 @@ def setUp(self):
47
47
self .s = self .thetype (word )
48
48
self .d = dict .fromkeys (word )
49
49
50
- # TODO: RUSTPYTHON
51
- @unittest .expectedFailure
52
50
def test_new_or_init (self ):
53
51
self .assertRaises (TypeError , self .thetype , [], 2 )
54
52
self .assertRaises (TypeError , set ().__init__ , a = 1 )
@@ -386,8 +384,6 @@ class TestSet(TestJointOps, unittest.TestCase):
386
384
def test_contains (self ):
387
385
super ().test_contains ()
388
386
389
- # TODO: RUSTPYTHON
390
- @unittest .expectedFailure
391
387
def test_init (self ):
392
388
s = self .thetype ()
393
389
s .__init__ (self .word )
Original file line number Diff line number Diff line change @@ -54,10 +54,7 @@ impl PyValue for PyDict {
54
54
impl PyDict {
55
55
#[ pyslot]
56
56
fn tp_new ( class : PyTypeRef , _args : FuncArgs , vm : & VirtualMachine ) -> PyResult < PyRef < Self > > {
57
- PyDict {
58
- entries : DictContentType :: default ( ) ,
59
- }
60
- . into_ref_with_type ( vm, class)
57
+ PyDict :: default ( ) . into_ref_with_type ( vm, class)
61
58
}
62
59
63
60
#[ pymethod( magic) ]
Original file line number Diff line number Diff line change @@ -391,16 +391,21 @@ impl PyList {
391
391
#[ pyslot]
392
392
fn tp_new (
393
393
cls : PyTypeRef ,
394
- iterable : OptionalArg < PyObjectRef > ,
394
+ _iterable : OptionalArg < PyObjectRef > ,
395
395
vm : & VirtualMachine ,
396
396
) -> PyResult < PyRef < Self > > {
397
- let elements = if let OptionalArg :: Present ( iterable) = iterable {
397
+ PyList :: default ( ) . into_ref_with_type ( vm, cls)
398
+ }
399
+
400
+ #[ pymethod( name = "__init__" ) ]
401
+ fn init ( & self , iterable : OptionalArg < PyObjectRef > , vm : & VirtualMachine ) -> PyResult < ( ) > {
402
+ let mut elements = if let OptionalArg :: Present ( iterable) = iterable {
398
403
vm. extract_elements ( & iterable) ?
399
404
} else {
400
405
vec ! [ ]
401
406
} ;
402
-
403
- PyList :: from ( elements ) . into_ref_with_type ( vm , cls )
407
+ std :: mem :: swap ( self . borrow_vec_mut ( ) . deref_mut ( ) , & mut elements ) ;
408
+ Ok ( ( ) )
404
409
}
405
410
}
406
411
Original file line number Diff line number Diff line change @@ -78,14 +78,6 @@ impl PySetInner {
78
78
Ok ( set)
79
79
}
80
80
81
- fn from_arg ( iterable : OptionalArg < PyIterable > , vm : & VirtualMachine ) -> PyResult < PySetInner > {
82
- if let OptionalArg :: Present ( iterable) = iterable {
83
- Self :: new ( iterable, vm)
84
- } else {
85
- Ok ( PySetInner :: default ( ) )
86
- }
87
- }
88
-
89
81
fn len ( & self ) -> usize {
90
82
self . content . len ( )
91
83
}
@@ -318,13 +310,21 @@ impl PySet {
318
310
#[ pyslot]
319
311
fn tp_new (
320
312
cls : PyTypeRef ,
321
- iterable : OptionalArg < PyIterable > ,
313
+ _iterable : OptionalArg < PyIterable > ,
322
314
vm : & VirtualMachine ,
323
315
) -> PyResult < PyRef < Self > > {
324
- Self {
325
- inner : PySetInner :: from_arg ( iterable, vm) ?,
316
+ PySet :: default ( ) . into_ref_with_type ( vm, cls)
317
+ }
318
+
319
+ #[ pymethod( magic) ]
320
+ fn init ( & self , iterable : OptionalArg < PyIterable > , vm : & VirtualMachine ) -> PyResult < ( ) > {
321
+ if self . len ( ) > 0 {
322
+ self . clear ( ) ;
326
323
}
327
- . into_ref_with_type ( vm, cls)
324
+ if let OptionalArg :: Present ( it) = iterable {
325
+ self . update ( Args :: new ( vec ! [ it] ) , vm) ?;
326
+ }
327
+ Ok ( ( ) )
328
328
}
329
329
330
330
#[ pymethod( name = "__len__" ) ]
You can’t perform that action at this time.
0 commit comments