Skip to content

Commit 2c14709

Browse files
committed
async/await are now always keywords
pycodestyle no longer supports python 3.6
1 parent 8c79b21 commit 2c14709

File tree

3 files changed

+1
-126
lines changed

3 files changed

+1
-126
lines changed

docs/intro.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,6 @@ This is the current list of error and warning codes:
413413
+------------+----------------------------------------------------------------------+
414414
| W605 | invalid escape sequence '\x' |
415415
+------------+----------------------------------------------------------------------+
416-
| W606 | 'async' and 'await' are reserved keywords starting with Python 3.7 |
417-
+------------+----------------------------------------------------------------------+
418416

419417

420418
**(*)** In the default configuration, the checks **E121**, **E123**, **E126**, **E133**,

pycodestyle.py

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102

103103
PyCF_ONLY_AST = 1024
104104
SINGLETONS = frozenset(['False', 'None', 'True'])
105-
KEYWORDS = frozenset(keyword.kwlist + ['print', 'async']) - SINGLETONS
105+
KEYWORDS = frozenset(keyword.kwlist + ['print']) - SINGLETONS
106106
UNARY_OPERATORS = frozenset(['>>', '**', '*', '+', '-'])
107107
ARITHMETIC_OP = frozenset(['**', '*', '/', '//', '+', '-', '@'])
108108
WS_OPTIONAL_OPERATORS = ARITHMETIC_OP.union(['^', '&', '|', '<<', '>>', '%'])
@@ -493,7 +493,6 @@ def missing_whitespace_after_keyword(logical_line, tokens):
493493
if (tok0.end == tok1.start and
494494
keyword.iskeyword(tok0.string) and
495495
tok0.string not in SINGLETONS and
496-
tok0.string not in ('async', 'await') and
497496
not (tok0.string == 'except' and tok1.string == '*') and
498497
not (tok0.string == 'yield' and tok1.string == ')') and
499498
tok1.string not in ':\n'):
@@ -1645,76 +1644,6 @@ def python_3000_invalid_escape_sequence(logical_line, tokens, noqa):
16451644
pos = string.find('\\', pos + 1)
16461645

16471646

1648-
@register_check
1649-
def python_3000_async_await_keywords(logical_line, tokens):
1650-
"""'async' and 'await' are reserved keywords starting at Python 3.7.
1651-
1652-
W606: async = 42
1653-
W606: await = 42
1654-
Okay: async def read(db):\n data = await db.fetch('SELECT ...')
1655-
"""
1656-
# The Python tokenize library before Python 3.5 recognizes
1657-
# async/await as a NAME token. Therefore, use a state machine to
1658-
# look for the possible async/await constructs as defined by the
1659-
# Python grammar:
1660-
# https://docs.python.org/3/reference/grammar.html
1661-
1662-
state = None
1663-
for token_type, text, start, end, line in tokens:
1664-
error = False
1665-
1666-
if token_type == tokenize.NL:
1667-
continue
1668-
1669-
if state is None:
1670-
if token_type == tokenize.NAME:
1671-
if text == 'async':
1672-
state = ('async_stmt', start)
1673-
elif text == 'await':
1674-
state = ('await', start)
1675-
elif (token_type == tokenize.NAME and
1676-
text in ('def', 'for')):
1677-
state = ('define', start)
1678-
1679-
elif state[0] == 'async_stmt':
1680-
if token_type == tokenize.NAME and text in ('def', 'with', 'for'):
1681-
# One of funcdef, with_stmt, or for_stmt. Return to
1682-
# looking for async/await names.
1683-
state = None
1684-
else:
1685-
error = True
1686-
elif state[0] == 'await':
1687-
if token_type == tokenize.NAME:
1688-
# An await expression. Return to looking for async/await
1689-
# names.
1690-
state = None
1691-
elif token_type == tokenize.OP and text == '(':
1692-
state = None
1693-
else:
1694-
error = True
1695-
elif state[0] == 'define':
1696-
if token_type == tokenize.NAME and text in ('async', 'await'):
1697-
error = True
1698-
else:
1699-
state = None
1700-
1701-
if error:
1702-
yield (
1703-
state[1],
1704-
"W606 'async' and 'await' are reserved keywords starting with "
1705-
"Python 3.7",
1706-
)
1707-
state = None
1708-
1709-
# Last token
1710-
if state is not None:
1711-
yield (
1712-
state[1],
1713-
"W606 'async' and 'await' are reserved keywords starting with "
1714-
"Python 3.7",
1715-
)
1716-
1717-
17181647
########################################################################
17191648
@register_check
17201649
def maximum_doc_length(logical_line, max_doc_length, noqa, tokens):

testsuite/W60.py

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -29,55 +29,3 @@
2929
regex = '''
3030
\w
3131
''' # noqa
32-
#: W606
33-
async = 42
34-
#: W606
35-
await = 42
36-
#: W606
37-
await 42
38-
#: W606
39-
await 'test'
40-
#: W606
41-
def async():
42-
pass
43-
#: W606
44-
def await():
45-
pass
46-
#: W606
47-
class async:
48-
pass
49-
#: W606
50-
class await:
51-
pass
52-
#: Okay
53-
async def read_data(db):
54-
data = await db.fetch('SELECT ...')
55-
#: Okay
56-
if await fut:
57-
pass
58-
if (await fut):
59-
pass
60-
if await fut + 1:
61-
pass
62-
if (await fut) + 1:
63-
pass
64-
pair = await fut, 'spam'
65-
pair = (await fut), 'spam'
66-
with await fut, open():
67-
pass
68-
with (await fut), open():
69-
pass
70-
await foo()['spam'].baz()()
71-
return await coro()
72-
return (await coro())
73-
res = await coro() ** 2
74-
res = (await coro()) ** 2
75-
func(a1=await coro(), a2=0)
76-
func(a1=(await coro()), a2=0)
77-
await foo() + await bar()
78-
(await foo()) + (await bar())
79-
-await foo()
80-
-(await foo())
81-
(await
82-
foo())
83-
await(await foo())

0 commit comments

Comments
 (0)