diff options
Diffstat (limited to 'Python/codegen.c')
-rw-r--r-- | Python/codegen.c | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/Python/codegen.c b/Python/codegen.c index ed06724..fd2260a 100644 --- a/Python/codegen.c +++ b/Python/codegen.c @@ -763,19 +763,18 @@ _PyCodegen_Body(compiler *c, location loc, asdl_stmt_seq *stmts) PyObject *docstring = _PyAST_GetDocString(stmts); if (docstring) { first_instr = 1; - /* if not -OO mode, set docstring */ - if (OPTIMIZATION_LEVEL(c) < 2) { - PyObject *cleandoc = _PyCompile_CleanDoc(docstring); - if (cleandoc == NULL) { - return ERROR; - } - stmt_ty st = (stmt_ty)asdl_seq_GET(stmts, 0); - assert(st->kind == Expr_kind); - location loc = LOC(st->v.Expr.value); - ADDOP_LOAD_CONST(c, loc, cleandoc); - Py_DECREF(cleandoc); - RETURN_IF_ERROR(codegen_nameop(c, NO_LOCATION, &_Py_ID(__doc__), Store)); + /* set docstring */ + assert(OPTIMIZATION_LEVEL(c) < 2); + PyObject *cleandoc = _PyCompile_CleanDoc(docstring); + if (cleandoc == NULL) { + return ERROR; } + stmt_ty st = (stmt_ty)asdl_seq_GET(stmts, 0); + assert(st->kind == Expr_kind); + location loc = LOC(st->v.Expr.value); + ADDOP_LOAD_CONST(c, loc, cleandoc); + Py_DECREF(cleandoc); + RETURN_IF_ERROR(codegen_nameop(c, NO_LOCATION, &_Py_ID(__doc__), Store)); } } for (Py_ssize_t i = first_instr; i < asdl_seq_LEN(stmts); i++) { @@ -1230,18 +1229,13 @@ codegen_function_body(compiler *c, stmt_ty s, int is_async, Py_ssize_t funcflags Py_ssize_t first_instr = 0; PyObject *docstring = _PyAST_GetDocString(body); + assert(OPTIMIZATION_LEVEL(c) < 2 || docstring == NULL); if (docstring) { first_instr = 1; - /* if not -OO mode, add docstring */ - if (OPTIMIZATION_LEVEL(c) < 2) { - docstring = _PyCompile_CleanDoc(docstring); - if (docstring == NULL) { - _PyCompile_ExitScope(c); - return ERROR; - } - } - else { - docstring = NULL; + docstring = _PyCompile_CleanDoc(docstring); + if (docstring == NULL) { + _PyCompile_ExitScope(c); + return ERROR; } } Py_ssize_t idx = _PyCompile_AddConst(c, docstring ? docstring : Py_None); |