File tree 1 file changed +22
-0
lines changed 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,29 @@ def visit_If(self, node: ast.If) -> None:
26
26
)
27
27
self .generic_visit (node )
28
28
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
+
29
50
IfFinder ().visit (tree )
51
+ PEP570Finder ().visit (tree )
30
52
return errors
31
53
32
54
You can’t perform that action at this time.
0 commit comments