Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 13602e2

Browse files
committed
calculate ste_has_docstring in symtable.c
1 parent 12f6b10 commit 13602e2

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

Python/codegen.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -773,9 +773,6 @@ _PyCodegen_Body(compiler *c, location loc, asdl_stmt_seq *stmts, bool is_interac
773773
location loc = LOC(st->v.Expr.value);
774774
ADDOP_LOAD_CONST(c, loc, cleandoc);
775775

776-
PySTEntryObject *ste = SYMTABLE_ENTRY(c);
777-
ste->ste_has_docstring = 1;
778-
779776
Py_DECREF(cleandoc);
780777
RETURN_IF_ERROR(codegen_nameop(c, NO_LOCATION, &_Py_ID(__doc__), Store));
781778
}
@@ -1229,7 +1226,6 @@ codegen_function_body(compiler *c, stmt_ty s, int is_async, Py_ssize_t funcflags
12291226
Py_ssize_t first_instr = 0;
12301227
PyObject *docstring = _PyAST_GetDocString(body);
12311228
assert(OPTIMIZATION_LEVEL(c) < 2 || docstring == NULL);
1232-
PySTEntryObject *ste = SYMTABLE_ENTRY(c);
12331229
if (docstring) {
12341230
first_instr = 1;
12351231
docstring = _PyCompile_CleanDoc(docstring);
@@ -1238,13 +1234,13 @@ codegen_function_body(compiler *c, stmt_ty s, int is_async, Py_ssize_t funcflags
12381234
return ERROR;
12391235
}
12401236
Py_ssize_t idx = _PyCompile_AddConst(c, docstring);
1241-
ste->ste_has_docstring = 1;
12421237
RETURN_IF_ERROR_IN_SCOPE(c, idx < 0 ? ERROR : SUCCESS);
12431238
}
12441239
Py_XDECREF(docstring);
12451240

12461241
NEW_JUMP_TARGET_LABEL(c, start);
12471242
USE_LABEL(c, start);
1243+
PySTEntryObject *ste = SYMTABLE_ENTRY(c);
12481244
bool add_stopiteration_handler = ste->ste_coroutine || ste->ste_generator;
12491245
if (add_stopiteration_handler) {
12501246
/* codegen_wrap_in_stopiteration_handler will push a block, so we need to account for that */

Python/symtable.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,10 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
18431843
return 0;
18441844
}
18451845

1846+
if (_PyAST_GetDocString(s->v.FunctionDef.body)) {
1847+
new_ste->ste_has_docstring = 1;
1848+
}
1849+
18461850
if (!symtable_visit_annotations(st, s, s->v.FunctionDef.args,
18471851
s->v.FunctionDef.returns, new_ste)) {
18481852
Py_DECREF(new_ste);
@@ -2170,6 +2174,10 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
21702174
return 0;
21712175
}
21722176

2177+
if (_PyAST_GetDocString(s->v.FunctionDef.body)) {
2178+
new_ste->ste_has_docstring = 1;
2179+
}
2180+
21732181
if (!symtable_visit_annotations(st, s, s->v.AsyncFunctionDef.args,
21742182
s->v.AsyncFunctionDef.returns, new_ste)) {
21752183
Py_DECREF(new_ste);

0 commit comments

Comments
 (0)