From a89e5bb0cf950e635653c38a517cdb530820f2b0 Mon Sep 17 00:00:00 2001 From: Akuli Date: Wed, 29 Dec 2021 18:50:11 +0200 Subject: [PATCH] Relax check_new_syntax.py to allow elif statements for old versions (#6729) --- tests/check_new_syntax.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/check_new_syntax.py b/tests/check_new_syntax.py index 71f7b837a..1b8c3372b 100755 --- a/tests/check_new_syntax.py +++ b/tests/check_new_syntax.py @@ -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, "