diff options
author | Ian Lee <IanLee1521@gmail.com> | 2014-12-18 01:54:20 -0800 |
---|---|---|
committer | Ian Lee <IanLee1521@gmail.com> | 2014-12-29 10:39:33 -0800 |
commit | eaf09d1ae4a92bd0982b5757f2872d0583f7a3d3 (patch) | |
tree | 188d22ef6aa41327b665190f4ecca81bfaf3f4f7 /pep8.py | |
parent | a21598e67abeb557f85855cdc04106c7c212f09b (diff) | |
download | pep8-eaf09d1ae4a92bd0982b5757f2872d0583f7a3d3.tar.gz |
Allow spaces around equals sign of an annotated function definition parameter; issue #357
Diffstat (limited to 'pep8.py')
-rwxr-xr-x | pep8.py | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -754,6 +754,8 @@ def whitespace_around_named_parameter_equals(logical_line, tokens): Okay: boolean(a != b) Okay: boolean(a <= b) Okay: boolean(a >= b) + Okay: def foo(arg: int = 42): + Okay: def f(x: int, y=15, z: float = 0.123) -> list: E251: def complex(real, imag = 0.0): E251: return magic(r = real, i = imag) @@ -761,6 +763,8 @@ def whitespace_around_named_parameter_equals(logical_line, tokens): parens = 0 no_space = False prev_end = None + annotated_func_arg = False + in_def = logical_line.startswith('def') message = "E251 unexpected spaces around keyword / parameter equals" for token_type, text, start, end, line in tokens: if token_type == tokenize.NL: @@ -774,7 +778,11 @@ def whitespace_around_named_parameter_equals(logical_line, tokens): parens += 1 elif text == ')': parens -= 1 - elif parens and text == '=': + elif in_def and text == ':': + annotated_func_arg = True + elif parens and text == ',': + annotated_func_arg = False + elif parens and text == '=' and not annotated_func_arg: no_space = True if start != prev_end: yield (prev_end, message) |