Skip to content
This repository was archived by the owner on Jul 27, 2023. It is now read-only.

Commit e1f02fc

Browse files
authored
Fix Vec::to_pyo3_ast (RustPython#63)
1 parent d4084fb commit e1f02fc

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

ast/src/pyo3.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ 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
42+
.iter()
43+
.map(|item| item.to_pyo3_ast(py))
44+
.collect::<Result<Vec<_>, _>>()?;
45+
let list = PyList::new(py, elts);
4646
Ok(list.into())
4747
}
4848
}

0 commit comments

Comments
 (0)