summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lee <IanLee1521@gmail.com>2014-12-18 01:54:20 -0800
committerIan Lee <IanLee1521@gmail.com>2014-12-18 01:54:20 -0800
commitae1000095558c782fe5cc745b2bd5e4b6dfccc52 (patch)
treeeaa9cf651c019ad9b49e0006d4ea0f60aac2e4ec
parent53d4741dbae96d0435fd8c55176611cc38816369 (diff)
downloadpep8-ae1000095558c782fe5cc745b2bd5e4b6dfccc52.tar.gz
Allow spaces around equals sign of an annotated function definition parameter; issue #357
-rw-r--r--CHANGES.txt2
-rwxr-xr-xpep8.py10
2 files changed, 11 insertions, 1 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index d0ae802..b61ee7f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -32,6 +32,8 @@ Changes:
* Add ``.tox/`` to default excludes. (Issue #335)
+* 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)
diff --git a/pep8.py b/pep8.py
index 914d7fd..7579494 100755
--- a/pep8.py
+++ b/pep8.py
@@ -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)