Skip to content

Commit d5f14fc

Browse files
committed
extract compiler_codegen from compiler_mod
1 parent f09da28 commit d5f14fc

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Python/compile.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,15 +2145,13 @@ compiler_body(struct compiler *c, location loc, asdl_stmt_seq *stmts)
21452145
return 1;
21462146
}
21472147

2148-
static PyCodeObject *
2149-
compiler_mod(struct compiler *c, mod_ty mod)
2148+
static int
2149+
compiler_codegen(struct compiler *c, mod_ty mod)
21502150
{
2151-
PyCodeObject *co;
2152-
int addNone = 1;
21532151
_Py_DECLARE_STR(anon_module, "<module>");
21542152
if (!compiler_enter_scope(c, &_Py_STR(anon_module), COMPILER_SCOPE_MODULE,
21552153
mod, 1)) {
2156-
return NULL;
2154+
return 0;
21572155
}
21582156
location loc = LOCATION(1, 1, 0, 0);
21592157
switch (mod->kind) {
@@ -2172,15 +2170,24 @@ compiler_mod(struct compiler *c, mod_ty mod)
21722170
break;
21732171
case Expression_kind:
21742172
VISIT_IN_SCOPE(c, expr, mod->v.Expression.body);
2175-
addNone = 0;
21762173
break;
21772174
default:
21782175
PyErr_Format(PyExc_SystemError,
21792176
"module kind %d should not be possible",
21802177
mod->kind);
21812178
return 0;
21822179
}
2183-
co = assemble(c, addNone);
2180+
return 1;
2181+
}
2182+
2183+
static PyCodeObject *
2184+
compiler_mod(struct compiler *c, mod_ty mod)
2185+
{
2186+
int addNone = mod->kind != Expression_kind;
2187+
if (!compiler_codegen(c, mod)) {
2188+
return NULL;
2189+
}
2190+
PyCodeObject *co = assemble(c, addNone);
21842191
compiler_exit_scope(c);
21852192
return co;
21862193
}

0 commit comments

Comments
 (0)