Skip to content

Commit 725e0f2

Browse files
committed
Merge pull request #361 from jcrocholl/issue-357
Allow spaces around equals sign of an annotated function definition
2 parents a21598e + 219db61 commit 725e0f2

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,13 +754,16 @@ 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):
757758
758759
E251: def complex(real, imag = 0.0):
759760
E251: return magic(r = real, i = imag)
760761
"""
761762
parens = 0
762763
no_space = False
763764
prev_end = None
765+
annotated_func_arg = False
766+
in_def = logical_line.startswith('def')
764767
message = "E251 unexpected spaces around keyword / parameter equals"
765768
for token_type, text, start, end, line in tokens:
766769
if token_type == tokenize.NL:
@@ -774,10 +777,17 @@ def whitespace_around_named_parameter_equals(logical_line, tokens):
774777
parens += 1
775778
elif text == ')':
776779
parens -= 1
777-
elif parens and text == '=':
780+
elif in_def and text == ':' and parens == 1:
781+
annotated_func_arg = True
782+
elif parens and text == ',' and parens == 1:
783+
annotated_func_arg = False
784+
elif parens and text == '=' and not annotated_func_arg:
778785
no_space = True
779786
if start != prev_end:
780787
yield (prev_end, message)
788+
if not parens:
789+
annotated_func_arg = False
790+
781791
prev_end = end
782792

783793

testsuite/E25.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ def foo(bar = False):
2929
foo(bar=(1 <= 1))
3030
(options, args) = parser.parse_args()
3131
d[type(None)] = _deepcopy_atomic
32+
33+
# Annotated Function Definitions
34+
#: Okay
35+
def munge(input: AnyStr, sep: AnyStr = None, limit=1000) -> AnyStr:
36+
pass

0 commit comments

Comments
 (0)