Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a lint forbidding PEP-570 syntax #10660

Merged
merged 4 commits into from
Sep 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/check_new_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,29 @@ def visit_If(self, node: ast.If) -> None:
)
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


Expand Down