Index: Python/symtable.c =================================================================== --- Python/symtable.c (revision 70632) +++ Python/symtable.c (working copy) @@ -476,7 +476,8 @@ char buf[300]; const char* trailer; - if (ste->ste_type != FunctionBlock || !ste->ste_unoptimized + if ((ste->ste_type != FunctionBlock && ste->ste_type != ClassBlock) + || !ste->ste_unoptimized || !(ste->ste_free || ste->ste_child_free)) return 1; Index: Lib/test/test_compile.py =================================================================== --- Lib/test/test_compile.py (revision 70632) +++ Lib/test/test_compile.py (working copy) @@ -460,6 +460,20 @@ ast.body = [_ast.BoolOp()] self.assertRaises(TypeError, compile, ast, '', 'exec') + def test_exec_inside_class(self): + source = """if 1: + def f(): + a = 2 + class C: + exec 'a = 42' + abc = a +""" + try: + exec source + except SyntaxError: + pass + else: + raise Exception("DID NOT RAISE") def test_main(): test_support.run_unittest(TestSpecifics)