diff --git a/pycodestyle.py b/pycodestyle.py index 3324850a..5f79a257 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -1045,17 +1045,16 @@ 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() - elif ( - text == ':' and ( - # def f(arg: tp = default): ... - (in_def and paren_stack == ['(']) or - # def f[T: tp = default](): ... - # class C[T: tp = default](): ... - (in_generic and paren_stack == ['[']) - ) - ): + # def f(arg: tp = default): ... + elif text == ':' and in_def and paren_stack == ['(']: annotated_func_arg = True elif len(paren_stack) == 1 and text == ',': annotated_func_arg = False diff --git a/testing/data/python313.py b/testing/data/python313.py index 5247ae9c..5540aced 100644 --- a/testing/data/python313.py +++ b/testing/data/python313.py @@ -1,9 +1,18 @@ type Alias[T: (int, str) = str] = list[T] +type Alias2[T = str] = list[T] class C[T: (int, str) = str]: pass +class C2[T = str]: + pass + + def f[T: (int, str) = str](t: T) -> T: pass + + +def f2[T = str](t: T) -> T: + pass