Skip to content

Commit 38aad70

Browse files
add async/await functionality to Python (#57)
1 parent 50c8fee commit 38aad70

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

code2flow/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def separate_namespaces(tree):
177177
nodes = []
178178
body = []
179179
for el in tree.body:
180-
if type(el) == ast.FunctionDef:
180+
if type(el) in (ast.FunctionDef, ast.AsyncFunctionDef):
181181
nodes.append(el)
182182
elif type(el) == ast.ClassDef:
183183
groups.append(el)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import asyncio
2+
3+
class A:
4+
def __init__(self):
5+
pass
6+
async def test(self):
7+
print("hello world")
8+
9+
async def main():
10+
a = A()
11+
await a.test()
12+
13+
asyncio.run(main())

tests/testdata.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,18 @@
241241
"expected_edges": [],
242242
"expected_nodes": ["file_b::(global)", "file_b::b", "file_b::c"]
243243
},
244+
{
245+
"test_name": "async_basic",
246+
"directory": "async_basic",
247+
"kwargs": {},
248+
"expected_edges": [["async_basic::main", "async_basic::A.__init__"],
249+
["async_basic::(global)", "async_basic::main"],
250+
["async_basic::main", "async_basic::A.test"]],
251+
"expected_nodes": ["async_basic::(global)",
252+
"async_basic::A.__init__",
253+
"async_basic::A.test",
254+
"async_basic::main"]
255+
},
244256
{
245257
"test_name": "exclude_modules",
246258
"comment": "Correct name resolution when third-party modules are involved",

0 commit comments

Comments
 (0)