Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b7666a3

Browse files
committed
Issue #24619: More tests; fix nits in compiler.c
1 parent 8fb307c commit b7666a3

4 files changed

Lines changed: 9 additions & 9 deletions

File tree

Lib/test/badsyntax_async2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
async def foo(a:await something()):
1+
async def foo(a=await something()):
22
pass

Lib/test/test_coroutines.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,14 @@ def bar():
205205
return lambda a: await
206206
""",
207207

208-
"""async def foo(a: await b):
208+
"""await a()""",
209+
210+
"""async def foo(a=await b):
209211
pass
210212
""",
211213

212214
"""def baz():
213-
async def foo(a: await b):
215+
async def foo(a=await b):
214216
pass
215217
""",
216218

@@ -271,10 +273,9 @@ async def bar():
271273
pass\nawait a
272274
"""]
273275

274-
ns = {}
275276
for code in samples:
276277
with self.subTest(code=code), self.assertRaises(SyntaxError):
277-
exec(code, ns, ns)
278+
compile(code, "<test>", "exec")
278279

279280
def test_goodsyntax_1(self):
280281
# Tests for issue 24619

Python/compile.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,13 +1749,12 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
17491749
arglength = asdl_seq_LEN(args->defaults);
17501750
arglength |= kw_default_count << 8;
17511751
arglength |= num_annotations << 16;
1752+
if (is_async)
1753+
co->co_flags |= CO_COROUTINE;
17521754
compiler_make_closure(c, co, arglength, qualname);
17531755
Py_DECREF(qualname);
17541756
Py_DECREF(co);
17551757

1756-
if (is_async)
1757-
co->co_flags |= CO_COROUTINE;
1758-
17591758
/* decorators */
17601759
for (i = 0; i < asdl_seq_LEN(decos); i++) {
17611760
ADDOP_I(c, CALL_FUNCTION, 1);

Python/symtable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ symtable_visit_annotations(struct symtable *st, stmt_ty s,
15421542
if (a->kwonlyargs && !symtable_visit_argannotations(st, a->kwonlyargs))
15431543
return 0;
15441544
if (returns)
1545-
VISIT(st, expr, s->v.FunctionDef.returns);
1545+
VISIT(st, expr, returns);
15461546
return 1;
15471547
}
15481548

0 commit comments

Comments
 (0)