From d0bf163641b244eb163f7dd262082ae6dcd21d05 Mon Sep 17 00:00:00 2001 From: Moreal Date: Tue, 24 Jan 2023 05:55:50 +0900 Subject: [PATCH 1/4] Register `array.array` to `collections.abc.MutableSequence` --- stdlib/src/array.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/stdlib/src/array.rs b/stdlib/src/array.rs index 26f5cd39f4..d05073ef1c 100644 --- a/stdlib/src/array.rs +++ b/stdlib/src/array.rs @@ -1,4 +1,31 @@ -pub(crate) use array::make_module; +use rustpython_vm::{PyObjectRef, VirtualMachine}; + +pub(crate) fn make_module(vm: &VirtualMachine) -> PyObjectRef { + let module = array::make_module(vm); + + let array = module + .get_attr("array", vm) + .expect("Expect array has arrat type."); + + // TODO: RUSTPYTHON + // FIXME: it should import 'collections.abc' instead of '_collection_abc' + let collections_abc = vm + .import("_collections_abc", None, 0) + .expect("Expect collections.abc exist."); + let mutable_sequence = collections_abc + .get_attr("MutableSequence", vm) + .expect("Expect collections.abc has MutableSequence type."); + + vm.invoke( + &mutable_sequence + .get_attr("register", vm) + .expect("Expect collections.abc.MutableSequence has register method."), + (array,), + ) + .expect("Expect collections.abc.MutableSequence.register(array.array) not fail."); + + module +} #[pymodule(name = "array")] mod array { From 778b8fdb2bfbd2acc1c610fd9f7ffb8244637773 Mon Sep 17 00:00:00 2001 From: Moreal Date: Tue, 24 Jan 2023 05:56:52 +0900 Subject: [PATCH 2/4] Unmark resolved tests --- Lib/test/test_array.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index 8fcd12bbfa..70fff5d0be 100644 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -30,8 +30,6 @@ def __init__(self, typecode, newarg=None): class MiscTest(unittest.TestCase): - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_array_is_sequence(self): self.assertIsInstance(array.array("B"), collections.abc.MutableSequence) self.assertIsInstance(array.array("B"), collections.abc.Reversible) From 03f0e717a7aa50dc24c93b9fa875e784bc010c56 Mon Sep 17 00:00:00 2001 From: Lee Dogeon Date: Tue, 24 Jan 2023 15:37:28 +0900 Subject: [PATCH 3/4] Correct typo Co-authored-by: Jim Fasarakis-Hilliard --- stdlib/src/array.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/src/array.rs b/stdlib/src/array.rs index d05073ef1c..e30711ab23 100644 --- a/stdlib/src/array.rs +++ b/stdlib/src/array.rs @@ -5,7 +5,7 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyObjectRef { let array = module .get_attr("array", vm) - .expect("Expect array has arrat type."); + .expect("Expect array has array type."); // TODO: RUSTPYTHON // FIXME: it should import 'collections.abc' instead of '_collection_abc' From 8284a7cb893de0b66f36eb48b9ce1e0d0bf282a2 Mon Sep 17 00:00:00 2001 From: Lee Dogeon Date: Tue, 24 Jan 2023 15:47:40 +0900 Subject: [PATCH 4/4] Import from `collections.abc` instead of `_collections_abc` Co-authored-by: Jim Fasarakis-Hilliard --- stdlib/src/array.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/stdlib/src/array.rs b/stdlib/src/array.rs index e30711ab23..cba0eb2fda 100644 --- a/stdlib/src/array.rs +++ b/stdlib/src/array.rs @@ -7,12 +7,13 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyObjectRef { .get_attr("array", vm) .expect("Expect array has array type."); - // TODO: RUSTPYTHON - // FIXME: it should import 'collections.abc' instead of '_collection_abc' let collections_abc = vm - .import("_collections_abc", None, 0) - .expect("Expect collections.abc exist."); - let mutable_sequence = collections_abc + .import("collections.abc", None, 0) + .expect("Expect collections exist."); + let abc = collections_abc + .get_attr("abc", vm) + .expect("Expect collections has abc submodule."); + let mutable_sequence = abc .get_attr("MutableSequence", vm) .expect("Expect collections.abc has MutableSequence type.");