From b7a599ffab0309da8bc7541877be0d097ebfc689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Fri, 13 Mar 2026 23:09:48 -0400 Subject: [PATCH 1/2] Parse async with multliple statements --- src/core/IronPython/Compiler/Parser.cs | 28 +++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/core/IronPython/Compiler/Parser.cs b/src/core/IronPython/Compiler/Parser.cs index 5033b6cf3..f76f0e161 100644 --- a/src/core/IronPython/Compiler/Parser.cs +++ b/src/core/IronPython/Compiler/Parser.cs @@ -1417,7 +1417,7 @@ private WithStatement ParseWithStmt() { var withItem = ParseWithItem(); List items = null; while (MaybeEat(TokenKind.Comma)) { - if (items == null) { + if (items is null) { items = new List(); } @@ -1427,7 +1427,7 @@ private WithStatement ParseWithStmt() { var header = GetEnd(); Statement body = ParseSuite(); - if (items != null) { + if (items is not null) { for (int i = items.Count - 1; i >= 0; i--) { var curItem = items[i]; var innerWith = new WithStatement(curItem.ContextManager, curItem.Variable, body); @@ -1480,12 +1480,34 @@ private AsyncWithStatement ParseAsyncWithStmt(int asyncStart) { } Eat(TokenKind.KeywordWith); + var withItem = ParseWithItem(); + List items = null; + while (MaybeEat(TokenKind.Comma)) { + if (items is null) { + items = new List(); + } + + items.Add(ParseWithItem()); + } + + var header = GetEnd(); Statement body = ParseSuite(); + if (items is not null) { + for (int i = items.Count - 1; i >= 0; i--) { + var curItem = items[i]; + var innerWith = new AsyncWithStatement(curItem.ContextManager, curItem.Variable, body); + innerWith.HeaderIndex = header; + innerWith.SetLoc(_globalParent, withItem.Start, GetEnd()); + body = innerWith; + header = GetEnd(); + } + } + AsyncWithStatement ret = new AsyncWithStatement(withItem.ContextManager, withItem.Variable, body); ret.HeaderIndex = header; - ret.SetLoc(_globalParent, asyncStart, GetEnd()); + ret.SetLoc(_globalParent, withItem.Start, GetEnd()); return ret; } From 7802846edce0f94e10295591125ab4dba31f754c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Fri, 13 Mar 2026 23:15:18 -0400 Subject: [PATCH 2/2] Re-enable grammar test --- src/core/IronPython.StdLib/lib/test/test_grammar.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/core/IronPython.StdLib/lib/test/test_grammar.py b/src/core/IronPython.StdLib/lib/test/test_grammar.py index e89748067..ac8d85a3c 100644 --- a/src/core/IronPython.StdLib/lib/test/test_grammar.py +++ b/src/core/IronPython.StdLib/lib/test/test_grammar.py @@ -1474,13 +1474,12 @@ async def foo(): pass async with manager() as (x, y): pass - # ironpython: todo implement this - #async with manager(), manager(): - # pass - #async with manager() as x, manager() as y: - # pass - #async with manager() as x, manager(): - # pass + async with manager(), manager(): + pass + async with manager() as x, manager() as y: + pass + async with manager() as x, manager(): + pass raise Done with self.assertRaises(Done):