summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Stapleton Cordasco <graffatcolmingov@gmail.com>2019-01-23 08:00:56 -0600
committerGitHub <noreply@github.com>2019-01-23 08:00:56 -0600
commit8940d64045d908d5be84ba60e6eb7846e21adb7a (patch)
treee70eaa57f3b70aa2431db784055323b6517c4767
parent9f8240e510284dce52b4d4a4d6ec9e4e388d59bd (diff)
parent2a7629f18f7a27bb2ef4b70db7a7b57e730db8de (diff)
downloadpep8-8940d64045d908d5be84ba60e6eb7846e21adb7a.tar.gz
Merge pull request #819 from wwwjfy/issue-811
fix #811, corner cases for async/await check
-rwxr-xr-xpycodestyle.py14
-rw-r--r--testsuite/W60.py3
2 files changed, 17 insertions, 0 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index 4372e3b..9fc1874 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -1569,12 +1569,19 @@ def python_3000_async_await_keywords(logical_line, tokens):
for token_type, text, start, end, line in tokens:
error = False
+ if token_type == tokenize.NL:
+ continue
+
if state is None:
if token_type == tokenize.NAME:
if text == 'async':
state = ('async_stmt', start)
elif text == 'await':
state = ('await', start)
+ elif (token_type == tokenize.NAME and
+ text in ('def', 'for')):
+ state = ('define', start)
+
elif state[0] == 'async_stmt':
if token_type == tokenize.NAME and text in ('def', 'with', 'for'):
# One of funcdef, with_stmt, or for_stmt. Return to
@@ -1587,8 +1594,15 @@ def python_3000_async_await_keywords(logical_line, tokens):
# An await expression. Return to looking for async/await
# names.
state = None
+ elif token_type == tokenize.OP and text == '(':
+ state = None
else:
error = True
+ elif state[0] == 'define':
+ if token_type == tokenize.NAME and text in ('async', 'await'):
+ error = True
+ else:
+ state = None
if error:
yield (
diff --git a/testsuite/W60.py b/testsuite/W60.py
index 78b163e..42a8c6d 100644
--- a/testsuite/W60.py
+++ b/testsuite/W60.py
@@ -89,3 +89,6 @@ await foo() + await bar()
(await foo()) + (await bar())
-await foo()
-(await foo())
+(await
+ foo())
+await(await foo())