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

Skip to content

Commit 6d35043

Browse files
committed
Merge 3.5 (Issue #24687)
2 parents 9b7a244 + f315c1c commit 6d35043

4 files changed

Lines changed: 22 additions & 15 deletions

File tree

Lib/test/test_coroutines.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ def bar():
211211
pass
212212
""",
213213

214+
"""async def foo(a:await b):
215+
pass
216+
""",
217+
214218
"""def baz():
215219
async def foo(a=await b):
216220
pass

Lib/test/test_grammar.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,8 @@ def g(): f((yield from ()), 1)
534534
# Not allowed at class scope
535535
check_syntax_error(self, "class foo:yield 1")
536536
check_syntax_error(self, "class foo:yield from ()")
537-
537+
# Check annotation refleak on SyntaxError
538+
check_syntax_error(self, "def g(a:(yield)): pass")
538539

539540
def test_raise(self):
540541
# 'raise' test [',' test]

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ Core and Builtins
4848
- Issue #24619: New approach for tokenizing async/await. As a consequence,
4949
is is now possible to have one-line 'async def foo(): await ..' functions.
5050

51+
- Issue #24687: Plug refleak on SyntaxError in function parameters
52+
annotations.
53+
5154
Library
5255
-------
5356

Python/compile.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,32 +1559,31 @@ compiler_visit_argannotation(struct compiler *c, identifier id,
15591559
VISIT(c, expr, annotation);
15601560
mangled = _Py_Mangle(c->u->u_private, id);
15611561
if (!mangled)
1562-
return -1;
1562+
return 0;
15631563
if (PyList_Append(names, mangled) < 0) {
15641564
Py_DECREF(mangled);
1565-
return -1;
1565+
return 0;
15661566
}
15671567
Py_DECREF(mangled);
15681568
}
1569-
return 0;
1569+
return 1;
15701570
}
15711571

15721572
static int
15731573
compiler_visit_argannotations(struct compiler *c, asdl_seq* args,
15741574
PyObject *names)
15751575
{
1576-
int i, error;
1576+
int i;
15771577
for (i = 0; i < asdl_seq_LEN(args); i++) {
15781578
arg_ty arg = (arg_ty)asdl_seq_GET(args, i);
1579-
error = compiler_visit_argannotation(
1579+
if (!compiler_visit_argannotation(
15801580
c,
15811581
arg->arg,
15821582
arg->annotation,
1583-
names);
1584-
if (error)
1585-
return error;
1583+
names))
1584+
return 0;
15861585
}
1587-
return 0;
1586+
return 1;
15881587
}
15891588

15901589
static int
@@ -1604,16 +1603,16 @@ compiler_visit_annotations(struct compiler *c, arguments_ty args,
16041603
if (!names)
16051604
return -1;
16061605

1607-
if (compiler_visit_argannotations(c, args->args, names))
1606+
if (!compiler_visit_argannotations(c, args->args, names))
16081607
goto error;
16091608
if (args->vararg && args->vararg->annotation &&
1610-
compiler_visit_argannotation(c, args->vararg->arg,
1609+
!compiler_visit_argannotation(c, args->vararg->arg,
16111610
args->vararg->annotation, names))
16121611
goto error;
1613-
if (compiler_visit_argannotations(c, args->kwonlyargs, names))
1612+
if (!compiler_visit_argannotations(c, args->kwonlyargs, names))
16141613
goto error;
16151614
if (args->kwarg && args->kwarg->annotation &&
1616-
compiler_visit_argannotation(c, args->kwarg->arg,
1615+
!compiler_visit_argannotation(c, args->kwarg->arg,
16171616
args->kwarg->annotation, names))
16181617
goto error;
16191618

@@ -1622,7 +1621,7 @@ compiler_visit_annotations(struct compiler *c, arguments_ty args,
16221621
if (!return_str)
16231622
goto error;
16241623
}
1625-
if (compiler_visit_argannotation(c, return_str, returns, names)) {
1624+
if (!compiler_visit_argannotation(c, return_str, returns, names)) {
16261625
goto error;
16271626
}
16281627

0 commit comments

Comments
 (0)