summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Davydenko <iam@igordavydenko.com>2015-08-26 17:19:06 +0300
committerIgor Davydenko <iam@igordavydenko.com>2015-08-26 17:19:06 +0300
commitc2086d643a519ce2eb1c266b4cf1550755b75d73 (patch)
treee719d13a36db98627840e530ec388155d1c645c4
parent12653ca4dcf56f10ac041dae7a916e86343239ca (diff)
downloadpyflakes-c2086d643a519ce2eb1c266b4cf1550755b75d73.tar.gz
Support Python 3.5 async/await statements for Pyflakes.
-rw-r--r--pyflakes/checker.py9
-rw-r--r--pyflakes/test/test_other.py52
2 files changed, 58 insertions, 3 deletions
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index abd7f50..ddbd43b 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -649,8 +649,9 @@ class Checker(object):
pass
# "stmt" type nodes
- DELETE = PRINT = FOR = WHILE = IF = WITH = WITHITEM = RAISE = \
- TRYFINALLY = ASSERT = EXEC = EXPR = ASSIGN = handleChildren
+ DELETE = PRINT = FOR = ASYNCFOR = WHILE = IF = WITH = WITHITEM = \
+ ASYNCWITH = ASYNCWITHITEM = RAISE = TRYFINALLY = ASSERT = EXEC = \
+ EXPR = ASSIGN = handleChildren
CONTINUE = BREAK = PASS = ignore
@@ -752,7 +753,7 @@ class Checker(object):
self.scope.isGenerator = True
self.handleNode(node.value, node)
- YIELDFROM = YIELD
+ AWAIT = YIELDFROM = YIELD
def FUNCTIONDEF(self, node):
for deco in node.decorator_list:
@@ -762,6 +763,8 @@ class Checker(object):
if self.withDoctest:
self.deferFunction(lambda: self.handleDoctests(node))
+ ASYNCFUNCTIONDEF = FUNCTIONDEF
+
def LAMBDA(self, node):
args = []
annotations = []
diff --git a/pyflakes/test/test_other.py b/pyflakes/test/test_other.py
index 718d16f..384c4b3 100644
--- a/pyflakes/test/test_other.py
+++ b/pyflakes/test/test_other.py
@@ -988,3 +988,55 @@ class TestUnusedAssignment(TestCase):
def test_returnOnly(self):
"""Do not crash on lone "return"."""
self.flakes('return 2')
+
+
+class TestAsyncStatements(TestCase):
+
+ @skipIf(version_info < (3, 5), 'new in Python 3.5')
+ def test_asyncDef(self):
+ self.flakes('''
+ async def bar():
+ return 42
+ ''')
+
+ @skipIf(version_info < (3, 5), 'new in Python 3.5')
+ def test_asyncDefAwait(self):
+ self.flakes('''
+ async def read_data(db):
+ await db.fetch('SELECT ...')
+ ''')
+
+ @skipIf(version_info < (3, 5), 'new in Python 3.5')
+ def test_asyncDefUndefined(self):
+ self.flakes('''
+ async def bar():
+ return foo()
+ ''', m.UndefinedName)
+
+ @skipIf(version_info < (3, 5), 'new in Python 3.5')
+ def test_asyncFor(self):
+ self.flakes('''
+ async def read_data(db):
+ output = []
+ async for row in db.cursor():
+ output.append(row)
+ return output
+ ''')
+
+ @skipIf(version_info < (3, 5), 'new in Python 3.5')
+ def test_asyncWith(self):
+ self.flakes('''
+ async def commit(session, data):
+ async with session.transaction():
+ await session.update(data)
+ ''')
+
+ @skipIf(version_info < (3, 5), 'new in Python 3.5')
+ def test_asyncWithItem(self):
+ self.flakes('''
+ async def commit(session, data):
+ async with session.transaction() as trans:
+ await trans.begin()
+ ...
+ await trans.end()
+ ''')