mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 13:34:58 +08:00
Add a lint forbidding PEP-570 syntax (#10660)
This commit is contained in:
@@ -26,7 +26,29 @@ def check_new_syntax(tree: ast.AST, path: Path, stub: str) -> list[str]:
|
||||
)
|
||||
self.generic_visit(node)
|
||||
|
||||
class PEP570Finder(ast.NodeVisitor):
|
||||
def __init__(self) -> None:
|
||||
self.lineno: int | None = None
|
||||
|
||||
def _visit_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> None:
|
||||
old_lineno = self.lineno
|
||||
self.lineno = node.lineno
|
||||
self.generic_visit(node)
|
||||
self.lineno = old_lineno
|
||||
|
||||
visit_FunctionDef = visit_AsyncFunctionDef = _visit_function
|
||||
|
||||
def visit_arguments(self, node: ast.arguments) -> None:
|
||||
if node.posonlyargs:
|
||||
assert isinstance(self.lineno, int)
|
||||
errors.append(
|
||||
f"{path}:{self.lineno}: PEP-570 syntax cannot be used in typeshed yet. "
|
||||
f"Prefix parameter names with `__` to indicate positional-only parameters"
|
||||
)
|
||||
self.generic_visit(node)
|
||||
|
||||
IfFinder().visit(tree)
|
||||
PEP570Finder().visit(tree)
|
||||
return errors
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user