summaryrefslogtreecommitdiff
path: root/pycodestyle.py
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2017-01-24 05:07:29 -0800
committerIan Cordasco <sigmavirus24@users.noreply.github.com>2017-01-24 07:07:29 -0600
commit30c7c4822db6db1a68672b1d6c6d951eacae4ae6 (patch)
tree837940d085fa6ca181e4e84773e0f575bc137a5b /pycodestyle.py
parentd7d61542bf579a41dd33f2920f3214c62c49fd47 (diff)
downloadpep8-30c7c4822db6db1a68672b1d6c6d951eacae4ae6.tar.gz
Report E704 for async def as well (#611)
Fix detection of 'async def' (with multiple spaces) so that it also reports E704
Diffstat (limited to 'pycodestyle.py')
-rwxr-xr-xpycodestyle.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index 559048e..0f14209 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -121,6 +121,8 @@ KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS))
OPERATOR_REGEX = re.compile(r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+)(\s*)')
LAMBDA_REGEX = re.compile(r'\blambda\b')
HUNK_REGEX = re.compile(r'^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$')
+STARTSWITH_DEF_REGEX = re.compile(r'^(async\s+def|def)')
+STARTSWITH_TOP_LEVEL_REGEX = re.compile(r'^(async\s+def|def|class|@)')
# Work around Python < 2.6 behaviour, which does not generate NL after
# a comment which is on a line by itself.
@@ -272,7 +274,7 @@ def blank_lines(logical_line, blank_lines, indent_level, line_number,
yield 0, "E304 blank lines found after function decorator"
elif blank_lines > 2 or (indent_level and blank_lines == 2):
yield 0, "E303 too many blank lines (%d)" % blank_lines
- elif logical_line.startswith(('def ', 'async def', 'class ', '@')):
+ elif STARTSWITH_TOP_LEVEL_REGEX.match(logical_line):
if indent_level:
if not (blank_before or previous_indent_level < indent_level or
DOCSTRING_REGEX.match(previous_logical)):
@@ -813,7 +815,7 @@ def whitespace_around_named_parameter_equals(logical_line, tokens):
no_space = False
prev_end = None
annotated_func_arg = False
- in_def = logical_line.startswith(('def', 'async def'))
+ in_def = bool(STARTSWITH_DEF_REGEX.match(logical_line))
message = "E251 unexpected spaces around keyword / parameter equals"
for token_type, text, start, end, line in tokens:
if token_type == tokenize.NL:
@@ -1000,7 +1002,7 @@ def compound_statements(logical_line):
yield 0, ("E731 do not assign a lambda expression, use a "
"def")
break
- if line.startswith('def '):
+ if STARTSWITH_DEF_REGEX.match(line):
yield 0, "E704 multiple statements on one line (def)"
else:
yield found, "E701 multiple statements on one line (colon)"