Skip to content

Commit eaf09d1

Browse files
committed
Allow spaces around equals sign of an annotated function definition parameter; issue #357
1 parent a21598e commit eaf09d1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Changes:
3434

3535
* Do not report E121 or E126 in the default configuration. (Issues #256 / #316)
3636

37+
* Allow spaces around the equals sign in an annotated function. (Issue #357)
38+
3739
Bug fixes:
3840

3941
* Don't crash if Checker.build_tokens_line() returns None. (Issue #306)

pep8.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,13 +754,17 @@ def whitespace_around_named_parameter_equals(logical_line, tokens):
754754
Okay: boolean(a != b)
755755
Okay: boolean(a <= b)
756756
Okay: boolean(a >= b)
757+
Okay: def foo(arg: int = 42):
758+
Okay: def f(x: int, y=15, z: float = 0.123) -> list:
757759
758760
E251: def complex(real, imag = 0.0):
759761
E251: return magic(r = real, i = imag)
760762
"""
761763
parens = 0
762764
no_space = False
763765
prev_end = None
766+
annotated_func_arg = False
767+
in_def = logical_line.startswith('def')
764768
message = "E251 unexpected spaces around keyword / parameter equals"
765769
for token_type, text, start, end, line in tokens:
766770
if token_type == tokenize.NL:
@@ -774,7 +778,11 @@ def whitespace_around_named_parameter_equals(logical_line, tokens):
774778
parens += 1
775779
elif text == ')':
776780
parens -= 1
777-
elif parens and text == '=':
781+
elif in_def and text == ':':
782+
annotated_func_arg = True
783+
elif parens and text == ',':
784+
annotated_func_arg = False
785+
elif parens and text == '=' and not annotated_func_arg:
778786
no_space = True
779787
if start != prev_end:
780788
yield (prev_end, message)

0 commit comments

Comments
 (0)