diff -r 12ad8c975766 Lib/test/test_ast.py --- a/Lib/test/test_ast.py Sat Aug 06 09:32:11 2011 +0300 +++ b/Lib/test/test_ast.py Sat Aug 06 20:13:00 2011 -0500 @@ -381,6 +381,17 @@ compile(m, "", "exec") self.assertIn("string must be of type str", str(cm.exception)) + def test_empty_function(self): + # issue12608: FunctionDef with empty body list crashes 'compile' + f = ast.Interactive(body=[ + ast.FunctionDef( + name="foo", + args=ast.arguments( + args=[], vararg=None, kwarg=None, defaults=[], + kwonlyargs=[], kw_defaults=[]), + body=[], decorator_list=[])]) + ast.fix_missing_locations(f) + compile(f, "", "single") class ASTHelpers_Test(unittest.TestCase): diff -r 12ad8c975766 Python/compile.c --- a/Python/compile.c Sat Aug 06 09:32:11 2011 +0300 +++ b/Python/compile.c Sat Aug 06 20:13:00 2011 -0500 @@ -1471,7 +1471,7 @@ return 0; st = (stmt_ty)asdl_seq_GET(s->v.FunctionDef.body, 0); - docstring = compiler_isdocstring(st); + docstring = st ? compiler_isdocstring(st): 0; if (docstring && c->c_optimize < 2) first_const = st->v.Expr.value->v.Str.s; if (compiler_add_o(c, c->u->u_consts, first_const) < 0) {