|
3 | 3 |
|
4 | 4 | import argparse |
5 | 5 | import ast |
6 | | -import contextlib |
7 | 6 | import logging |
8 | 7 | import re |
9 | 8 | import sys |
@@ -1016,8 +1015,6 @@ def __init__(self, filename: str) -> None: |
1016 | 1015 | self.string_literals_allowed = NestingCounter() |
1017 | 1016 | self.long_strings_allowed = NestingCounter() |
1018 | 1017 | self.in_function = NestingCounter() |
1019 | | - self.in_class = NestingCounter() |
1020 | | - self.in_protocol = NestingCounter() |
1021 | 1018 | self.visiting_arg = NestingCounter() |
1022 | 1019 | self.Y061_suppressed = NestingCounter() |
1023 | 1020 |
|
@@ -1744,8 +1741,8 @@ def visit_ClassDef(self, node: ast.ClassDef) -> None: |
1744 | 1741 |
|
1745 | 1742 | self.generic_visit(node) |
1746 | 1743 | self._check_class_bases(node.bases) |
1747 | | - self.check_class_pass_and_ellipsis(node) |
1748 | 1744 | self.enclosing_class_ctx = old_context |
| 1745 | + self.check_class_pass_and_ellipsis(node) |
1749 | 1746 |
|
1750 | 1747 | def check_class_pass_and_ellipsis(self, node: ast.ClassDef) -> None: |
1751 | 1748 | # empty class body should contain "..." not "pass" |
@@ -2126,7 +2123,7 @@ def check_self_typevars(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> N |
2126 | 2123 | return_annotation=return_annotation, |
2127 | 2124 | ) |
2128 | 2125 |
|
2129 | | - def check_arg_kinds(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> None: |
| 2126 | + def check_protocol_param_kinds(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> None: |
2130 | 2127 | for pos_or_kw in node.args.args[1:]: # exclude "self" |
2131 | 2128 | if pos_or_kw.arg.startswith("__"): |
2132 | 2129 | continue |
@@ -2187,8 +2184,8 @@ def _visit_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> None: |
2187 | 2184 | self._check_pep570_syntax_used_where_applicable(node) |
2188 | 2185 | if self.enclosing_class_ctx is not None: |
2189 | 2186 | self.check_self_typevars(node) |
2190 | | - if self.in_protocol.active: |
2191 | | - self.check_arg_kinds(node) |
| 2187 | + if self.enclosing_class_ctx.is_protocol_class: |
| 2188 | + self.check_protocol_param_kinds(node) |
2192 | 2189 |
|
2193 | 2190 | def visit_arg(self, node: ast.arg) -> None: |
2194 | 2191 | if _is_NoReturn(node.annotation): |
|
0 commit comments