Skip to content

Commit 2445edd

Browse files
authored
Check for typing.Deque, typing.FrozenSet and typing.DefaultDict in check_new_syntax.py (#6362)
1 parent c685c2d commit 2445edd

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

tests/check_new_syntax.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,21 @@ def visit_Subscript(self, node: ast.Subscript) -> None:
2626
if node.value.id == "Optional":
2727
new_syntax = f"{ast.unparse(node.slice)} | None"
2828
errors.append(f"{path}:{node.lineno}: Use PEP 604 syntax for Optional, e.g. `{new_syntax}`")
29-
if node.value.id == "List":
30-
new_syntax = f"list[{ast.unparse(node.slice)}]"
29+
if node.value.id in {"List", "FrozenSet"}:
30+
new_syntax = f"{node.value.id.lower()}[{ast.unparse(node.slice)}]"
3131
errors.append(f"{path}:{node.lineno}: Use built-in generics, e.g. `{new_syntax}`")
32+
if node.value.id == "Deque":
33+
new_syntax = f"collections.deque[{ast.unparse(node.slice)}]"
34+
errors.append(f"{path}:{node.lineno}: Use `collections.deque` instead of `typing.Deque`, e.g. `{new_syntax}`")
3235
if node.value.id == "Dict":
3336
new_syntax = f"dict[{unparse_without_tuple_parens(node.slice)}]"
3437
errors.append(f"{path}:{node.lineno}: Use built-in generics, e.g. `{new_syntax}`")
38+
if node.value.id == "DefaultDict":
39+
new_syntax = f"collections.defaultdict[{unparse_without_tuple_parens(node.slice)}]"
40+
errors.append(
41+
f"{path}:{node.lineno}: Use `collections.defaultdict` instead of `typing.DefaultDict`, "
42+
f"e.g. `{new_syntax}`"
43+
)
3544
# Tuple[Foo, ...] must be allowed because of mypy bugs
3645
if node.value.id == "Tuple" and not (
3746
isinstance(node.slice, ast.Tuple) and len(node.slice.elts) == 2 and is_dotdotdot(node.slice.elts[1])

0 commit comments

Comments
 (0)