From e1f02fced740cdd99593ae4b14bcfcac725e9e02 Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" <69878+youknowone@users.noreply.github.com> Date: Mon, 22 May 2023 15:15:05 +0900 Subject: [PATCH] Fix Vec::to_pyo3_ast (#63) --- ast/src/pyo3.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ast/src/pyo3.rs b/ast/src/pyo3.rs index e54fff2..74e5172 100644 --- a/ast/src/pyo3.rs +++ b/ast/src/pyo3.rs @@ -38,11 +38,11 @@ impl ToPyo3Ast for Option { impl ToPyo3Ast for Vec { fn to_pyo3_ast(&self, py: Python) -> PyResult> { - let list = PyList::empty(py); - for item in self { - let py_item = item.to_pyo3_ast(py)?; - list.append(py_item)?; - } + let elts = self + .iter() + .map(|item| item.to_pyo3_ast(py)) + .collect::, _>>()?; + let list = PyList::new(py, elts); Ok(list.into()) } }