Relax check_new_syntax.py to allow elif statements for old versions (#6729)

This commit is contained in:
Akuli
2021-12-29 18:50:11 +02:00
committed by GitHub
parent a82a4bc62b
commit a89e5bb0cf

View File

@@ -130,7 +130,12 @@ def check_new_syntax(tree: ast.AST, path: Path) -> list[str]:
class IfFinder(ast.NodeVisitor):
def visit_If(self, node: ast.If) -> None:
if isinstance(node.test, ast.Compare) and ast.unparse(node.test).startswith("sys.version_info < ") and node.orelse:
if (
isinstance(node.test, ast.Compare)
and ast.unparse(node.test).startswith("sys.version_info < ")
and node.orelse
and not (len(node.orelse) == 1 and isinstance(node.orelse[0], ast.If)) # elif statement (#6728)
):
new_syntax = "if " + ast.unparse(node.test).replace("<", ">=", 1)
errors.append(
f"{path}:{node.lineno}: When using if/else with sys.version_info, "