Skip to content

Commit 17baca4

Browse files
taionsigmavirus24
authored andcommitted
Fix detection of annotated argument defaults
This improves E252 to allow default arguments like `_default(f=1)`. Closes gh-753
1 parent d8f10a9 commit 17baca4

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

pycodestyle.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -937,17 +937,17 @@ def whitespace_around_named_parameter_equals(logical_line, tokens):
937937
parens -= 1
938938
elif in_def and text == ':' and parens == 1:
939939
annotated_func_arg = True
940-
elif parens and text == ',' and parens == 1:
940+
elif parens == 1 and text == ',':
941941
annotated_func_arg = False
942942
elif parens and text == '=':
943-
if not annotated_func_arg:
944-
no_space = True
945-
if start != prev_end:
946-
yield (prev_end, message)
947-
else:
943+
if annotated_func_arg and parens == 1:
948944
require_space = True
949945
if start == prev_end:
950946
yield (prev_end, missing_message)
947+
else:
948+
no_space = True
949+
if start != prev_end:
950+
yield (prev_end, message)
951951
if not parens:
952952
annotated_func_arg = False
953953

testsuite/E25.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,6 @@ async def add(a: int = 0, b: int = 0) -> int:
4545
#: E252:1:15 E252:1:16 E252:1:27 E252:1:36
4646
def add(a: int=0, b: int =0, c: int= 0) -> int:
4747
return a + b + c
48+
#: Okay
49+
def add(a: int = _default(name='f')):
50+
return a

0 commit comments

Comments
 (0)