mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-124022: Fix bug where class docstring is removed in interactive mode (#124023)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
cfe6074d1f
commit
a9594a34c6
5 changed files with 37 additions and 12 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue