diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2024-09-13 14:06:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-13 14:06:06 (GMT) |
commit | a9594a34c62487961be86c0925daaa43bb467bb9 (patch) | |
tree | e7674482ca96b3e045ab3d5d9a7e56bbba5da0f0 /Python | |
parent | cfe6074d1fa81cf0684fbf8a623616441a1966e7 (diff) | |
download | cpython-a9594a34c62487961be86c0925daaa43bb467bb9.zip cpython-a9594a34c62487961be86c0925daaa43bb467bb9.tar.gz cpython-a9594a34c62487961be86c0925daaa43bb467bb9.tar.bz2 |
gh-124022: Fix bug where class docstring is removed in interactive mode (#124023)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Diffstat (limited to 'Python')
-rw-r--r-- | Python/codegen.c | 6 | ||||
-rw-r--r-- | Python/compile.c | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/Python/codegen.c b/Python/codegen.c index 2ca5db1..5565d30 100644 --- a/Python/codegen.c +++ b/Python/codegen.c @@ -746,7 +746,7 @@ _PyCodegen_Expression(compiler *c, expr_ty e) and for annotations. */ int -_PyCodegen_Body(compiler *c, location loc, asdl_stmt_seq *stmts) +_PyCodegen_Body(compiler *c, location loc, asdl_stmt_seq *stmts, bool is_interactive) { /* If from __future__ import annotations is active, * every annotated class and module should have __annotations__. @@ -758,7 +758,7 @@ _PyCodegen_Body(compiler *c, location loc, asdl_stmt_seq *stmts) return SUCCESS; } Py_ssize_t first_instr = 0; - if (!IS_INTERACTIVE(c)) { + if (!is_interactive) { /* A string literal on REPL prompt is not a docstring */ PyObject *docstring = _PyAST_GetDocString(stmts); if (docstring) { first_instr = 1; @@ -1432,7 +1432,7 @@ codegen_class_body(compiler *c, stmt_ty s, int firstlineno) ADDOP_N_IN_SCOPE(c, loc, STORE_DEREF, &_Py_ID(__classdict__), cellvars); } /* compile the body proper */ - RETURN_IF_ERROR_IN_SCOPE(c, _PyCodegen_Body(c, loc, s->v.ClassDef.body)); + RETURN_IF_ERROR_IN_SCOPE(c, _PyCodegen_Body(c, loc, s->v.ClassDef.body, false)); PyObject *static_attributes = _PyCompile_StaticAttributesAsTuple(c); if (static_attributes == NULL) { _PyCompile_ExitScope(c); diff --git a/Python/compile.c b/Python/compile.c index d54c320..e1d2c30 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -790,13 +790,13 @@ compiler_codegen(compiler *c, mod_ty mod) switch (mod->kind) { case Module_kind: { asdl_stmt_seq *stmts = mod->v.Module.body; - RETURN_IF_ERROR(_PyCodegen_Body(c, start_location(stmts), stmts)); + RETURN_IF_ERROR(_PyCodegen_Body(c, start_location(stmts), stmts, false)); break; } case Interactive_kind: { c->c_interactive = 1; asdl_stmt_seq *stmts = mod->v.Interactive.body; - RETURN_IF_ERROR(_PyCodegen_Body(c, start_location(stmts), stmts)); + RETURN_IF_ERROR(_PyCodegen_Body(c, start_location(stmts), stmts, true)); break; } case Expression_kind: { |