mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-01-09 21:12:25 +08:00
Use lowercase tuple where possible (#6170)
This commit is contained in:
@@ -14,6 +14,9 @@ def check_new_syntax(tree: ast.AST, path: Path) -> list[str]:
|
||||
return ast.unparse(node)[1:-1]
|
||||
return ast.unparse(node)
|
||||
|
||||
def is_dotdotdot(node: ast.AST) -> bool:
|
||||
return isinstance(node, ast.Constant) and node.s is Ellipsis
|
||||
|
||||
class OldSyntaxFinder(ast.NodeVisitor):
|
||||
def visit_Subscript(self, node: ast.Subscript) -> None:
|
||||
if isinstance(node.value, ast.Name):
|
||||
@@ -29,6 +32,14 @@ def check_new_syntax(tree: ast.AST, path: Path) -> list[str]:
|
||||
if node.value.id == "Dict":
|
||||
new_syntax = f"dict[{unparse_without_tuple_parens(node.slice)}]"
|
||||
errors.append(f"{path}:{node.lineno}: Use built-in generics, e.g. `{new_syntax}`")
|
||||
# Tuple[Foo, ...] must be allowed because of mypy bugs
|
||||
if node.value.id == "Tuple" and not (
|
||||
isinstance(node.slice, ast.Tuple)
|
||||
and len(node.slice.elts) == 2
|
||||
and is_dotdotdot(node.slice.elts[1])
|
||||
):
|
||||
new_syntax = f"tuple[{unparse_without_tuple_parens(node.slice)}]"
|
||||
errors.append(f"{path}:{node.lineno}: Use built-in generics, e.g. `{new_syntax}`")
|
||||
|
||||
self.generic_visit(node)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user