Skip to content

Commit 19eaf85

Browse files
committed
set ste_has_docstring for class and module
1 parent 1b156e7 commit 19eaf85

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Python/codegen.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,10 +1231,12 @@ codegen_function_body(compiler *c, stmt_ty s, int is_async, Py_ssize_t funcflags
12311231
RETURN_IF_ERROR(
12321232
codegen_enter_scope(c, name, scope_type, (void *)s, firstlineno, NULL, &umd));
12331233

1234+
PySTEntryObject *ste = SYMTABLE_ENTRY(c);
12341235
Py_ssize_t first_instr = 0;
12351236
PyObject *docstring = _PyAST_GetDocString(body);
12361237
assert(OPTIMIZATION_LEVEL(c) < 2 || docstring == NULL);
12371238
if (docstring) {
1239+
assert(ste->ste_has_docstring);
12381240
first_instr = 1;
12391241
docstring = _PyCompile_CleanDoc(docstring);
12401242
if (docstring == NULL) {
@@ -1248,7 +1250,6 @@ codegen_function_body(compiler *c, stmt_ty s, int is_async, Py_ssize_t funcflags
12481250

12491251
NEW_JUMP_TARGET_LABEL(c, start);
12501252
USE_LABEL(c, start);
1251-
PySTEntryObject *ste = SYMTABLE_ENTRY(c);
12521253
bool add_stopiteration_handler = ste->ste_coroutine || ste->ste_generator;
12531254
if (add_stopiteration_handler) {
12541255
/* codegen_wrap_in_stopiteration_handler will push a block, so we need to account for that */

Python/symtable.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,12 @@ _PySymtable_Build(mod_ty mod, PyObject *filename, _PyFutureFeatures *future)
434434
switch (mod->kind) {
435435
case Module_kind:
436436
seq = mod->v.Module.body;
437+
if (_PyAST_GetDocString(seq)) {
438+
PySTEntryObject *mod_ste = _PySymtable_Lookup(st, mod);
439+
assert(mod_ste);
440+
mod_ste->ste_has_docstring = 1;
441+
Py_DECREF(mod_ste);
442+
}
437443
for (i = 0; i < asdl_seq_LEN(seq); i++)
438444
if (!symtable_visit_stmt(st,
439445
(stmt_ty)asdl_seq_GET(seq, i)))
@@ -1909,6 +1915,14 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
19091915
return 0;
19101916
}
19111917
}
1918+
1919+
if (_PyAST_GetDocString(s->v.ClassDef.body)) {
1920+
PySTEntryObject *class_ste = _PySymtable_Lookup(st, s);
1921+
assert(class_ste);
1922+
class_ste->ste_has_docstring = 1;
1923+
Py_DECREF(class_ste);
1924+
}
1925+
19121926
VISIT_SEQ(st, stmt, s->v.ClassDef.body);
19131927
if (!symtable_exit_block(st))
19141928
return 0;

0 commit comments

Comments
 (0)