From: Daniele Varrazzo Date: Sun, 8 Oct 2023 09:02:23 +0000 (+0200) Subject: refactor(async_to_sync): create new object without listing all the attributes X-Git-Tag: pool-3.2.0~12^2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a6fd29abd3959aa14e7109f7d2f1721240edd151;p=thirdparty%2Fpsycopg.git refactor(async_to_sync): create new object without listing all the attributes --- diff --git a/tools/async_to_sync.py b/tools/async_to_sync.py index 28f98a783..02758d391 100755 --- a/tools/async_to_sync.py +++ b/tools/async_to_sync.py @@ -68,27 +68,19 @@ def tree_to_str(tree: ast.AST, filepath: Path) -> str: class AsyncToSync(ast.NodeTransformer): def visit_AsyncFunctionDef(self, node: ast.AsyncFunctionDef) -> ast.AST: - new_node = ast.FunctionDef( - name=node.name, - args=node.args, - body=node.body, - decorator_list=node.decorator_list, - returns=node.returns, - ) + new_node = ast.FunctionDef(**node.__dict__) ast.copy_location(new_node, node) self.visit(new_node) return new_node def visit_AsyncFor(self, node: ast.AsyncFor) -> ast.AST: - new_node = ast.For( - target=node.target, iter=node.iter, body=node.body, orelse=node.orelse - ) + new_node = ast.For(**node.__dict__) ast.copy_location(new_node, node) self.visit(new_node) return new_node def visit_AsyncWith(self, node: ast.AsyncWith) -> ast.AST: - new_node = ast.With(items=node.items, body=node.body) + new_node = ast.With(**node.__dict__) ast.copy_location(new_node, node) self.visit(new_node) return new_node