summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt4
-rw-r--r--docs/intro.rst17
-rwxr-xr-xpep8.py18
-rw-r--r--testsuite/E25.py5
4 files changed, 38 insertions, 6 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 4e2adc0..1caba39 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -34,6 +34,10 @@ Changes:
* 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)
+
+* Allow trailing backslash if in an inline comment. (Issue #374)
+
Bug fixes:
* Don't crash if Checker.build_tokens_line() returns None. (Issue #306)
diff --git a/docs/intro.rst b/docs/intro.rst
index b5e3971..13a9553 100644
--- a/docs/intro.rst
+++ b/docs/intro.rst
@@ -183,17 +183,26 @@ Quick help is available on the command line::
Configuration
-------------
-The behaviour may be configured at two levels.
+The behaviour may be configured at two levels, the user and project levels.
+
+At the user level, settings are read from the following locations:
+
+If on Windows:
+ ``~\.pep8``
+
+Otherwise, if the :envvar:`XDG_CONFIG_HOME` environment variable is defined:
+ ``XDG_CONFIG_HOME/pep8``
+
+Else if :envvar:`XDG_CONFIG_HOME` is not defined:
+ ``~/.config/pep8``
-The user settings are read from the ``~/.config/pep8`` file and
-for Windows from the ``~\.pep8`` file.
Example::
[pep8]
ignore = E226,E302,E41
max-line-length = 160
-At the project level, a ``tox.ini`` file or a ``setup.cfg`` file is read if
+At the project level, a ``setup.cfg`` file or a ``tox.ini`` file is read if
present (``.pep8`` file is also supported, but it is deprecated). If none of
these files have a ``[pep8]`` section, no project specific configuration is
loaded.
diff --git a/pep8.py b/pep8.py
index 77c5df0..79497e2 100755
--- a/pep8.py
+++ b/pep8.py
@@ -754,6 +754,7 @@ 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):
E251: def complex(real, imag = 0.0):
E251: return magic(r = real, i = imag)
@@ -761,6 +762,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,10 +777,17 @@ def whitespace_around_named_parameter_equals(logical_line, tokens):
parens += 1
elif text == ')':
parens -= 1
- elif parens and text == '=':
+ elif in_def and text == ':' and parens == 1:
+ annotated_func_arg = True
+ elif parens and text == ',' and parens == 1:
+ annotated_func_arg = False
+ elif parens and text == '=' and not annotated_func_arg:
no_space = True
if start != prev_end:
yield (prev_end, message)
+ if not parens:
+ annotated_func_arg = False
+
prev_end = end
@@ -962,10 +972,14 @@ def explicit_line_join(logical_line, tokens):
Okay: aaa = [123,\n 123]
Okay: aaa = ("bbb "\n "ccc")
Okay: aaa = "bbb " \\n "ccc"
+ Okay: aaa = 123 # \\
"""
prev_start = prev_end = parens = 0
+ comment = False
for token_type, text, start, end, line in tokens:
- if start[0] != prev_start and parens and backslash:
+ if token_type == tokenize.COMMENT:
+ comment = True
+ if start[0] != prev_start and parens and backslash and not comment:
yield backslash, "E502 the backslash is redundant between brackets"
if end[0] != prev_end:
if line.rstrip('\r\n').endswith('\\'):
diff --git a/testsuite/E25.py b/testsuite/E25.py
index 9b7ff69..ad8db88 100644
--- a/testsuite/E25.py
+++ b/testsuite/E25.py
@@ -29,3 +29,8 @@ foo(bar=(1 >= 1))
foo(bar=(1 <= 1))
(options, args) = parser.parse_args()
d[type(None)] = _deepcopy_atomic
+
+# Annotated Function Definitions
+#: Okay
+def munge(input: AnyStr, sep: AnyStr = None, limit=1000) -> AnyStr:
+ pass