From d0bf163641b244eb163f7dd262082ae6dcd21d05 Mon Sep 17 00:00:00 2001 From: Moreal Date: Tue, 24 Jan 2023 05:55:50 +0900 Subject: [PATCH] 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 26f5cd39f..d05073ef1 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 {