Skip to content

Commit 13c626a

Browse files
committed
fix false positive with TypeVar defaults with more than one argument
1 parent 292cdd0 commit 13c626a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

pycodestyle.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,12 +1066,6 @@ def whitespace_around_named_parameter_equals(logical_line, tokens):
10661066
if token_type == tokenize.OP:
10671067
if text in '([':
10681068
paren_stack.append(text)
1069-
# PEP 696 defaults always use spaced-style `=`
1070-
# type A[T = default] = ...
1071-
# def f[T = default](): ...
1072-
# class C[T = default](): ...
1073-
if in_generic and paren_stack == ['[']:
1074-
annotated_func_arg = True
10751069
elif text in ')]' and paren_stack:
10761070
paren_stack.pop()
10771071
# def f(arg: tp = default): ...
@@ -1080,7 +1074,14 @@ def whitespace_around_named_parameter_equals(logical_line, tokens):
10801074
elif len(paren_stack) == 1 and text == ',':
10811075
annotated_func_arg = False
10821076
elif paren_stack and text == '=':
1083-
if annotated_func_arg and len(paren_stack) == 1:
1077+
if (
1078+
# PEP 696 defaults always use spaced-style `=`
1079+
# type A[T = default] = ...
1080+
# def f[T = default](): ...
1081+
# class C[T = default](): ...
1082+
(in_generic and paren_stack == ['[']) or
1083+
(annotated_func_arg and paren_stack == ['('])
1084+
):
10841085
require_space = True
10851086
if start == prev_end:
10861087
yield (prev_end, missing_message)

testing/data/python313.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ class C2[T = str]:
1010
pass
1111

1212

13+
class C3[T, U: str = str]:
14+
pass
15+
16+
1317
def f[T: (int, str) = str](t: T) -> T:
1418
pass
1519

0 commit comments

Comments
 (0)