Skip to content

Commit c484194

Browse files
committed
Fix Vec::to_pyo3_ast
1 parent d4084fb commit c484194

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

ast/src/pyo3.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,8 @@ impl<T: ToPyo3Ast> ToPyo3Ast for Option<T> {
3838

3939
impl<T: ToPyo3Ast> ToPyo3Ast for Vec<T> {
4040
fn to_pyo3_ast(&self, py: Python) -> PyResult<Py<PyAny>> {
41-
let list = PyList::empty(py);
42-
for item in self {
43-
let py_item = item.to_pyo3_ast(py)?;
44-
list.append(py_item)?;
45-
}
41+
let elts = self.iter().map(|item| item.to_pyo3_ast(py)).collect::<Result<Vec<_>, _>>()?;
42+
let list = PyList::new(py, elts);
4643
Ok(list.into())
4744
}
4845
}

0 commit comments

Comments
 (0)