Skip to content

Commit 8940d64

Browse files
authored
Merge pull request #819 from wwwjfy/issue-811
fix #811, corner cases for async/await check
2 parents 9f8240e + 2a7629f commit 8940d64

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pycodestyle.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,12 +1569,19 @@ def python_3000_async_await_keywords(logical_line, tokens):
15691569
for token_type, text, start, end, line in tokens:
15701570
error = False
15711571

1572+
if token_type == tokenize.NL:
1573+
continue
1574+
15721575
if state is None:
15731576
if token_type == tokenize.NAME:
15741577
if text == 'async':
15751578
state = ('async_stmt', start)
15761579
elif text == 'await':
15771580
state = ('await', start)
1581+
elif (token_type == tokenize.NAME and
1582+
text in ('def', 'for')):
1583+
state = ('define', start)
1584+
15781585
elif state[0] == 'async_stmt':
15791586
if token_type == tokenize.NAME and text in ('def', 'with', 'for'):
15801587
# One of funcdef, with_stmt, or for_stmt. Return to
@@ -1587,8 +1594,15 @@ def python_3000_async_await_keywords(logical_line, tokens):
15871594
# An await expression. Return to looking for async/await
15881595
# names.
15891596
state = None
1597+
elif token_type == tokenize.OP and text == '(':
1598+
state = None
15901599
else:
15911600
error = True
1601+
elif state[0] == 'define':
1602+
if token_type == tokenize.NAME and text in ('async', 'await'):
1603+
error = True
1604+
else:
1605+
state = None
15921606

15931607
if error:
15941608
yield (

testsuite/W60.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,6 @@ async def read_data(db):
8989
(await foo()) + (await bar())
9090
-await foo()
9191
-(await foo())
92+
(await
93+
foo())
94+
await(await foo())

0 commit comments

Comments
 (0)