Skip to content

Commit 2a7629f

Browse files
committed
fix #811, corner cases for async/await check
1 parent 3d37ea0 commit 2a7629f

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
@@ -1566,12 +1566,19 @@ def python_3000_async_await_keywords(logical_line, tokens):
15661566
for token_type, text, start, end, line in tokens:
15671567
error = False
15681568

1569+
if token_type == tokenize.NL:
1570+
continue
1571+
15691572
if state is None:
15701573
if token_type == tokenize.NAME:
15711574
if text == 'async':
15721575
state = ('async_stmt', start)
15731576
elif text == 'await':
15741577
state = ('await', start)
1578+
elif (token_type == tokenize.NAME and
1579+
text in ('def', 'for')):
1580+
state = ('define', start)
1581+
15751582
elif state[0] == 'async_stmt':
15761583
if token_type == tokenize.NAME and text in ('def', 'with', 'for'):
15771584
# One of funcdef, with_stmt, or for_stmt. Return to
@@ -1584,8 +1591,15 @@ def python_3000_async_await_keywords(logical_line, tokens):
15841591
# An await expression. Return to looking for async/await
15851592
# names.
15861593
state = None
1594+
elif token_type == tokenize.OP and text == '(':
1595+
state = None
15871596
else:
15881597
error = True
1598+
elif state[0] == 'define':
1599+
if token_type == tokenize.NAME and text in ('async', 'await'):
1600+
error = True
1601+
else:
1602+
state = None
15891603

15901604
if error:
15911605
yield (

testsuite/W60.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,6 @@ async def read_data(db):
8585
(await foo()) + (await bar())
8686
-await foo()
8787
-(await foo())
88+
(await
89+
foo())
90+
await(await foo())

0 commit comments

Comments
 (0)