Skip to content

Commit 78e815c

Browse files
authored
Merge pull request #4469 from moreal/array-register
Register `array.array` to `collections.abc.MutableSequence`
2 parents 685a7e8 + 8284a7c commit 78e815c

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

Lib/test/test_array.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ def __init__(self, typecode, newarg=None):
3030

3131
class MiscTest(unittest.TestCase):
3232

33-
# TODO: RUSTPYTHON
34-
@unittest.expectedFailure
3533
def test_array_is_sequence(self):
3634
self.assertIsInstance(array.array("B"), collections.abc.MutableSequence)
3735
self.assertIsInstance(array.array("B"), collections.abc.Reversible)

stdlib/src/array.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
1-
pub(crate) use array::make_module;
1+
use rustpython_vm::{PyObjectRef, VirtualMachine};
2+
3+
pub(crate) fn make_module(vm: &VirtualMachine) -> PyObjectRef {
4+
let module = array::make_module(vm);
5+
6+
let array = module
7+
.get_attr("array", vm)
8+
.expect("Expect array has array type.");
9+
10+
let collections_abc = vm
11+
.import("collections.abc", None, 0)
12+
.expect("Expect collections exist.");
13+
let abc = collections_abc
14+
.get_attr("abc", vm)
15+
.expect("Expect collections has abc submodule.");
16+
let mutable_sequence = abc
17+
.get_attr("MutableSequence", vm)
18+
.expect("Expect collections.abc has MutableSequence type.");
19+
20+
vm.invoke(
21+
&mutable_sequence
22+
.get_attr("register", vm)
23+
.expect("Expect collections.abc.MutableSequence has register method."),
24+
(array,),
25+
)
26+
.expect("Expect collections.abc.MutableSequence.register(array.array) not fail.");
27+
28+
module
29+
}
230

331
#[pymodule(name = "array")]
432
mod array {

0 commit comments

Comments
 (0)