Skip to content

Commit af97a12

Browse files
authored
Add a lint forbidding PEP-570 syntax (#10660)
1 parent 433204f commit af97a12

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/check_new_syntax.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,29 @@ def visit_If(self, node: ast.If) -> None:
2626
)
2727
self.generic_visit(node)
2828

29+
class PEP570Finder(ast.NodeVisitor):
30+
def __init__(self) -> None:
31+
self.lineno: int | None = None
32+
33+
def _visit_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> None:
34+
old_lineno = self.lineno
35+
self.lineno = node.lineno
36+
self.generic_visit(node)
37+
self.lineno = old_lineno
38+
39+
visit_FunctionDef = visit_AsyncFunctionDef = _visit_function
40+
41+
def visit_arguments(self, node: ast.arguments) -> None:
42+
if node.posonlyargs:
43+
assert isinstance(self.lineno, int)
44+
errors.append(
45+
f"{path}:{self.lineno}: PEP-570 syntax cannot be used in typeshed yet. "
46+
f"Prefix parameter names with `__` to indicate positional-only parameters"
47+
)
48+
self.generic_visit(node)
49+
2950
IfFinder().visit(tree)
51+
PEP570Finder().visit(tree)
3052
return errors
3153

3254

0 commit comments

Comments
 (0)