Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,12 +1066,6 @@ def whitespace_around_named_parameter_equals(logical_line, tokens):
if token_type == tokenize.OP:
if text in '([':
paren_stack.append(text)
# PEP 696 defaults always use spaced-style `=`
# type A[T = default] = ...
# def f[T = default](): ...
# class C[T = default](): ...
if in_generic and paren_stack == ['[']:
annotated_func_arg = True
elif text in ')]' and paren_stack:
paren_stack.pop()
# def f(arg: tp = default): ...
Expand All @@ -1080,7 +1074,14 @@ def whitespace_around_named_parameter_equals(logical_line, tokens):
elif len(paren_stack) == 1 and text == ',':
annotated_func_arg = False
elif paren_stack and text == '=':
if annotated_func_arg and len(paren_stack) == 1:
if (
# PEP 696 defaults always use spaced-style `=`
# type A[T = default] = ...
# def f[T = default](): ...
# class C[T = default](): ...
(in_generic and paren_stack == ['[']) or
(annotated_func_arg and paren_stack == ['('])
):
require_space = True
if start == prev_end:
yield (prev_end, missing_message)
Expand Down
4 changes: 4 additions & 0 deletions testing/data/python313.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class C2[T = str]:
pass


class C3[T, U: str = str]:
pass


def f[T: (int, str) = str](t: T) -> T:
pass

Expand Down