Skip to content

Commit 18c04f2

Browse files
authored
gh-142349: Fix ast.unparse for lazy import statements (#144893)
The unparser was not handling the `is_lazy` attribute on Import and ImportFrom AST nodes, causing lazy imports to be unparsed as regular imports. This broke the round-trip (parse → unparse → reparse) for any file containing `lazy import` statements.
1 parent 185a6e9 commit 18c04f2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Lib/_ast_unparse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ def visit_NamedExpr(self, node):
239239
self.traverse(node.value)
240240

241241
def visit_Import(self, node):
242-
self.fill("import ")
242+
self.fill("lazy import " if node.is_lazy else "import ")
243243
self.interleave(lambda: self.write(", "), self.traverse, node.names)
244244

245245
def visit_ImportFrom(self, node):
246-
self.fill("from ")
246+
self.fill("lazy from " if node.is_lazy else "from ")
247247
self.write("." * (node.level or 0))
248248
if node.module:
249249
self.write(node.module)

0 commit comments

Comments
 (0)