* Do not report E121 or E126 in the default configuration. (Issues #256 / #316)
+* Allow spaces around the equals sign in an annotated function. (Issue #357)
+
Bug fixes:
* Don't crash if Checker.build_tokens_line() returns None. (Issue #306)
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)
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:
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)