@@ -772,6 +772,10 @@ _PyCodegen_Body(compiler *c, location loc, asdl_stmt_seq *stmts, bool is_interac
772772 assert (st -> kind == Expr_kind );
773773 location loc = LOC (st -> v .Expr .value );
774774 ADDOP_LOAD_CONST (c , loc , cleandoc );
775+
776+ PySTEntryObject * ste = SYMTABLE_ENTRY (c );
777+ ste -> ste_has_docstring = 1 ;
778+
775779 Py_DECREF (cleandoc );
776780 RETURN_IF_ERROR (codegen_nameop (c , NO_LOCATION , & _Py_ID (__doc__ ), Store ));
777781 }
@@ -1225,21 +1229,22 @@ codegen_function_body(compiler *c, stmt_ty s, int is_async, Py_ssize_t funcflags
12251229 Py_ssize_t first_instr = 0 ;
12261230 PyObject * docstring = _PyAST_GetDocString (body );
12271231 assert (OPTIMIZATION_LEVEL (c ) < 2 || docstring == NULL );
1232+ PySTEntryObject * ste = SYMTABLE_ENTRY (c );
12281233 if (docstring ) {
12291234 first_instr = 1 ;
12301235 docstring = _PyCompile_CleanDoc (docstring );
12311236 if (docstring == NULL ) {
12321237 _PyCompile_ExitScope (c );
12331238 return ERROR ;
12341239 }
1240+ Py_ssize_t idx = _PyCompile_AddConst (c , docstring );
1241+ ste -> ste_has_docstring = 1 ;
1242+ RETURN_IF_ERROR_IN_SCOPE (c , idx < 0 ? ERROR : SUCCESS );
12351243 }
1236- Py_ssize_t idx = _PyCompile_AddConst (c , docstring ? docstring : Py_None );
12371244 Py_XDECREF (docstring );
1238- RETURN_IF_ERROR_IN_SCOPE (c , idx < 0 ? ERROR : SUCCESS );
12391245
12401246 NEW_JUMP_TARGET_LABEL (c , start );
12411247 USE_LABEL (c , start );
1242- PySTEntryObject * ste = SYMTABLE_ENTRY (c );
12431248 bool add_stopiteration_handler = ste -> ste_coroutine || ste -> ste_generator ;
12441249 if (add_stopiteration_handler ) {
12451250 /* codegen_wrap_in_stopiteration_handler will push a block, so we need to account for that */
0 commit comments