Skip to content

Commit 7fbe43a

Browse files
committed
Fix post-merge
1 parent 6dfb7e1 commit 7fbe43a

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

pyi.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import argparse
55
import ast
6-
import contextlib
76
import logging
87
import re
98
import sys
@@ -1016,8 +1015,6 @@ def __init__(self, filename: str) -> None:
10161015
self.string_literals_allowed = NestingCounter()
10171016
self.long_strings_allowed = NestingCounter()
10181017
self.in_function = NestingCounter()
1019-
self.in_class = NestingCounter()
1020-
self.in_protocol = NestingCounter()
10211018
self.visiting_arg = NestingCounter()
10221019
self.Y061_suppressed = NestingCounter()
10231020

@@ -1744,8 +1741,8 @@ def visit_ClassDef(self, node: ast.ClassDef) -> None:
17441741

17451742
self.generic_visit(node)
17461743
self._check_class_bases(node.bases)
1747-
self.check_class_pass_and_ellipsis(node)
17481744
self.enclosing_class_ctx = old_context
1745+
self.check_class_pass_and_ellipsis(node)
17491746

17501747
def check_class_pass_and_ellipsis(self, node: ast.ClassDef) -> None:
17511748
# empty class body should contain "..." not "pass"
@@ -2126,7 +2123,7 @@ def check_self_typevars(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> N
21262123
return_annotation=return_annotation,
21272124
)
21282125

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:
21302127
for pos_or_kw in node.args.args[1:]: # exclude "self"
21312128
if pos_or_kw.arg.startswith("__"):
21322129
continue
@@ -2187,8 +2184,8 @@ def _visit_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> None:
21872184
self._check_pep570_syntax_used_where_applicable(node)
21882185
if self.enclosing_class_ctx is not None:
21892186
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)
21922189

21932190
def visit_arg(self, node: ast.arg) -> None:
21942191
if _is_NoReturn(node.annotation):

tests/protocol_arg.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from typing import Protocol
22

33
class P(Protocol):
4-
def method1(self, arg: int) -> None: ... # Y062 Argument "arg" to protocol method "method1" should not be positional-or-keyword (suggestion: make it positional-only)
4+
def method1(self, arg: int) -> None: ... # Y067 Argument "arg" to protocol method "method1" should probably not be positional-or-keyword. Make it positional-only, since usually you don't want to mandate a specific argument name
55
def method2(self, arg: str, /) -> None: ...
66
def method3(self, *, arg: str) -> None: ...
7-
def method4(self, __arg: int) -> None: ...
8-
def method5(self, __arg: int, *, foo: str) -> None: ...
7+
def method4(self, arg: int, /) -> None: ...
8+
def method5(self, arg: int, /, *, foo: str) -> None: ...
99
def method6(self, arg, /, *, foo: str) -> None: ...

0 commit comments

Comments
 (0)