Skip to content

Commit

Permalink
Fix bugs in check_new_syntax.py (#7808)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored May 8, 2022
1 parent bb39bdf commit 8d8420b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/check_new_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ def visit_Subscript(self, node: ast.Subscript) -> None:
class OldSyntaxFinder(ast.NodeVisitor):
def visit_AnnAssign(self, node: ast.AnnAssign) -> None:
AnnotationUnionFinder().visit(node.annotation)
self.generic_visit(node)

def visit_arg(self, node: ast.arg) -> None:
if node.annotation is not None:
AnnotationUnionFinder().visit(node.annotation)
self.generic_visit(node)

def _visit_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> None:
if node.returns is not None:
Expand All @@ -62,10 +64,12 @@ def visit_AsyncFunctionDef(self, node: ast.AsyncFunctionDef) -> None:

def visit_Assign(self, node: ast.Assign) -> None:
NonAnnotationUnionFinder().visit(node.value)
self.generic_visit(node)

def visit_ClassDef(self, node: ast.ClassDef) -> None:
for base in node.bases:
NonAnnotationUnionFinder().visit(base)
self.generic_visit(node)

class ObjectClassdefFinder(ast.NodeVisitor):
def visit_ClassDef(self, node: ast.ClassDef) -> None:
Expand All @@ -80,10 +84,12 @@ class TextFinder(ast.NodeVisitor):
def visit_ImportFrom(self, node: ast.ImportFrom) -> None:
if node.module == "typing" and any(thing.name == "Text" for thing in node.names):
errors.append(f"{path}:{node.lineno}: Use `str` instead of `typing.Text` in a Python-3-only stub.")
self.generic_visit(node)

def visit_Attribute(self, node: ast.Attribute) -> None:
if isinstance(node.value, ast.Name) and node.value.id == "typing" and node.attr == "Text":
errors.append(f"{path}:{node.lineno}: Use `str` instead of `typing.Text` in a Python-3-only stub.")
self.generic_visit(node)

class IfFinder(ast.NodeVisitor):
def visit_If(self, node: ast.If) -> None:
Expand Down

0 comments on commit 8d8420b

Please sign in to comment.