# HG changeset patch # User Bastien Orivel # Date 1465834155 -7200 # Node ID 7ac23f4336b194e3627807805bc51a3e365e4a0c # Parent 2c1e2ce412638628842b01a652fc2e849c502d34 Add ast.AsyncWith. diff --git a/src/ast_convert.rs b/src/ast_convert.rs --- a/src/ast_convert.rs +++ b/src/ast_convert.rs @@ -544,6 +544,7 @@ fn parse_statement(py: Python, ast: PyOb let continue_type = ast_module.get(py, "Continue").unwrap(); let assert_type = ast_module.get(py, "Assert").unwrap(); let with_type = ast_module.get(py, "With").unwrap(); + let async_with_type = ast_module.get(py, "AsyncWith").unwrap(); let raise_type = ast_module.get(py, "Raise").unwrap(); let try_type = ast_module.get(py, "Try").unwrap(); @@ -695,13 +696,13 @@ fn parse_statement(py: Python, ast: PyOb let msg = parse_optional_expr(py, msg); stmt::Assert(test, msg) - } else if is_instance(&ast, &with_type) { + } else if is_instance(&ast, &with_type) || is_instance(&ast, &async_with_type) { let items = ast.getattr(py, "items").unwrap(); let body = ast.getattr(py, "body").unwrap(); let items = parse_list(py, items, parse_withitem); let body = parse_list(py, body, parse_statement); - stmt::With(items, body) + stmt::With(items, body, is_instance(&ast, &async_with_type)) } else if is_instance(&ast, &raise_type) { let exc = ast.getattr(py, "exc").unwrap(); let cause = ast.getattr(py, "cause").unwrap(); diff --git a/src/ast_dump.rs b/src/ast_dump.rs --- a/src/ast_dump.rs +++ b/src/ast_dump.rs @@ -354,9 +354,10 @@ impl stmt { } ) }, - stmt::With(items, body) => { - format!("{}with {}:\n{}", + stmt::With(items, body, async) => { + format!("{}{}with {}:\n{}", current_indent, + if async { "async " } else { "" }, vec_to_strings_vec(items).join(", "), statements_to_string(indent, body) ) diff --git a/src/python_ast.rs b/src/python_ast.rs --- a/src/python_ast.rs +++ b/src/python_ast.rs @@ -40,9 +40,10 @@ pub enum stmt { If(expr, Vec, Vec), // With(withitem* items, stmt* body) - With(Vec, Vec), + // AsyncWith(withitem* items, stmt* body) + // If the last field is true, then it's an AsyncWith. + With(Vec, Vec, bool), - // AsyncWith(withitem* items, stmt* body) //AsyncWith(Vec, Vec) // Raise(expr? exc, expr? cause) diff --git a/tests/test_parse_files/test_async_with.py b/tests/test_parse_files/test_async_with.py new file mode 100644 --- /dev/null +++ b/tests/test_parse_files/test_async_with.py @@ -0,0 +1,5 @@ +async def b(): + async with a: + pass + async with a() as b, c: + pass