]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
refactor(async_to_sync): create new object without listing all the attributes
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 8 Oct 2023 09:02:23 +0000 (11:02 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 11 Oct 2023 21:45:39 +0000 (23:45 +0200)
tools/async_to_sync.py

index 28f98a7831443b222a399ff54eb452f8dc471542..02758d391ef0710acb30dd09d0c2168dfc315d33 100755 (executable)
@@ -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