Skip to content

Commit 778d00d

Browse files
committed
handle PEP 696 generics without bounds
1 parent 24ce381 commit 778d00d

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

pycodestyle.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -1045,17 +1045,16 @@ def whitespace_around_named_parameter_equals(logical_line, tokens):
10451045
if token_type == tokenize.OP:
10461046
if text in '([':
10471047
paren_stack.append(text)
1048+
# PEP 696 defaults always use spaced-style `=`
1049+
# type A[T = default] = ...
1050+
# def f[T = default](): ...
1051+
# class C[T = default](): ...
1052+
if in_generic and paren_stack == ['[']:
1053+
annotated_func_arg = True
10481054
elif text in ')]' and paren_stack:
10491055
paren_stack.pop()
1050-
elif (
1051-
text == ':' and (
1052-
# def f(arg: tp = default): ...
1053-
(in_def and paren_stack == ['(']) or
1054-
# def f[T: tp = default](): ...
1055-
# class C[T: tp = default](): ...
1056-
(in_generic and paren_stack == ['['])
1057-
)
1058-
):
1056+
# def f(arg: tp = default): ...
1057+
elif text == ':' and in_def and paren_stack == ['(']:
10591058
annotated_func_arg = True
10601059
elif len(paren_stack) == 1 and text == ',':
10611060
annotated_func_arg = False

testing/data/python313.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
type Alias[T: (int, str) = str] = list[T]
2+
type Alias2[T = str] = list[T]
23

34

45
class C[T: (int, str) = str]:
56
pass
67

78

9+
class C2[T = str]:
10+
pass
11+
12+
813
def f[T: (int, str) = str](t: T) -> T:
914
pass
15+
16+
17+
def f2[T = str](t: T) -> T:
18+
pass

0 commit comments

Comments
 (0)