mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 13:04:46 +08:00
Relax check_new_syntax.py to allow elif statements for old versions (#6729)
This commit is contained in:
@@ -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, "
|
||||
|
||||
Reference in New Issue
Block a user