From: Pablo Galindo Salgado Date: Mon, 16 Feb 2026 22:57:49 +0000 (+0000) Subject: gh-142349: Fix ast.unparse for lazy import statements (#144893) X-Git-Tag: v3.15.0a7~265 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=18c04f2e2a7e47329e9eefc5f269afe2d68729b0;p=thirdparty%2FPython%2Fcpython.git 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. --- diff --git a/Lib/_ast_unparse.py b/Lib/_ast_unparse.py index 1c8741b5a554..0c3b1d3a9108 100644 --- a/Lib/_ast_unparse.py +++ b/Lib/_ast_unparse.py @@ -239,11 +239,11 @@ class Unparser(NodeVisitor): self.traverse(node.value) def visit_Import(self, node): - self.fill("import ") + self.fill("lazy import " if node.is_lazy else "import ") self.interleave(lambda: self.write(", "), self.traverse, node.names) def visit_ImportFrom(self, node): - self.fill("from ") + self.fill("lazy from " if node.is_lazy else "from ") self.write("." * (node.level or 0)) if node.module: self.write(node.module)