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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
calculate ste_has_docstring in symtable.c
  • Loading branch information
xuantengh committed Oct 30, 2024
commit 099a765f92b0b60a2054ef31b70fdace71d3d4ed
6 changes: 1 addition & 5 deletions Python/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,9 +784,6 @@ _PyCodegen_Body(compiler *c, location loc, asdl_stmt_seq *stmts, bool is_interac
location loc = LOC(st->v.Expr.value);
ADDOP_LOAD_CONST(c, loc, cleandoc);

PySTEntryObject *ste = SYMTABLE_ENTRY(c);
ste->ste_has_docstring = 1;

Py_DECREF(cleandoc);
RETURN_IF_ERROR(codegen_nameop(c, NO_LOCATION, &_Py_ID(__doc__), Store));
}
Expand Down Expand Up @@ -1240,7 +1237,6 @@ 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);
PySTEntryObject *ste = SYMTABLE_ENTRY(c);
if (docstring) {
first_instr = 1;
docstring = _PyCompile_CleanDoc(docstring);
Expand All @@ -1249,13 +1245,13 @@ codegen_function_body(compiler *c, stmt_ty s, int is_async, Py_ssize_t funcflags
return ERROR;
}
Py_ssize_t idx = _PyCompile_AddConst(c, docstring);
ste->ste_has_docstring = 1;
RETURN_IF_ERROR_IN_SCOPE(c, idx < 0 ? ERROR : SUCCESS);
Comment thread
xuantengh marked this conversation as resolved.
}
Py_XDECREF(docstring);

NEW_JUMP_TARGET_LABEL(c, start);
USE_LABEL(c, start);
PySTEntryObject *ste = SYMTABLE_ENTRY(c);
bool add_stopiteration_handler = ste->ste_coroutine || ste->ste_generator;
if (add_stopiteration_handler) {
/* codegen_wrap_in_stopiteration_handler will push a block, so we need to account for that */
Expand Down
8 changes: 8 additions & 0 deletions Python/symtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,10 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
return 0;
}

if (_PyAST_GetDocString(s->v.FunctionDef.body)) {
new_ste->ste_has_docstring = 1;
}

if (!symtable_visit_annotations(st, s, s->v.FunctionDef.args,
s->v.FunctionDef.returns, new_ste)) {
Py_DECREF(new_ste);
Expand Down Expand Up @@ -2170,6 +2174,10 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
return 0;
}

if (_PyAST_GetDocString(s->v.FunctionDef.body)) {
new_ste->ste_has_docstring = 1;
}

if (!symtable_visit_annotations(st, s, s->v.AsyncFunctionDef.args,
s->v.AsyncFunctionDef.returns, new_ste)) {
Py_DECREF(new_ste);
Expand Down