Skip to content

Commit b7c62ce

Browse files
authored
fix py313a5 deprecationwarning (#218)
1 parent 63560fa commit b7c62ce

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

tests/test_flake8_async.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,20 +458,24 @@ class SyncTransformer(ast.NodeTransformer):
458458
def visit_Await(self, node: ast.Await):
459459
return self.generic_visit(node.value)
460460

461-
def replace_async(self, node: ast.AST, target: type[ast.AST]) -> ast.AST:
461+
def replace_async(
462+
self, node: ast.AST, target: type[ast.AST], *args: object
463+
) -> ast.AST:
462464
node = self.generic_visit(node)
463-
newnode = target()
465+
# py313 gives DeprecationWarning if missing posargs, so we pass them even if we
466+
# overwrite __dict__ directly afterwards
467+
newnode = target(*args)
464468
newnode.__dict__ = node.__dict__
465469
return newnode
466470

467-
def visit_AsyncFunctionDef(self, node: ast.AST):
468-
return self.replace_async(node, ast.FunctionDef)
471+
def visit_AsyncFunctionDef(self, node: ast.AsyncFunctionDef):
472+
return self.replace_async(node, ast.FunctionDef, node.name, node.args)
469473

470-
def visit_AsyncWith(self, node: ast.AST):
474+
def visit_AsyncWith(self, node: ast.AsyncWith):
471475
return self.replace_async(node, ast.With)
472476

473-
def visit_AsyncFor(self, node: ast.AST):
474-
return self.replace_async(node, ast.For)
477+
def visit_AsyncFor(self, node: ast.AsyncFor):
478+
return self.replace_async(node, ast.For, node.target, node.iter)
475479

476480

477481
@pytest.mark.parametrize(("test", "path"), test_files)

0 commit comments

Comments
 (0)