mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-02-25 11:07:17 +08:00
tests/check_new_syntax.py: check order of if statements (#6423)
This commit is contained in:
@@ -117,7 +117,18 @@ def check_new_syntax(tree: ast.AST, path: Path) -> list[str]:
|
||||
self.old_syntax_finder().visit(node.returns)
|
||||
self.generic_visit(node)
|
||||
|
||||
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:
|
||||
new_syntax = "if " + ast.unparse(node.test).replace("<", ">=", 1)
|
||||
errors.append(
|
||||
f"{path}:{node.lineno}: When using if/else with sys.version_info, "
|
||||
f"put the code for new Python versions first, e.g. `{new_syntax}`"
|
||||
)
|
||||
self.generic_visit(node)
|
||||
|
||||
AnnotationFinder().visit(tree)
|
||||
IfFinder().visit(tree)
|
||||
return errors
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user