Skip to content

Commit 1b156e7

Browse files
committed
don't append None in annotation, lambda and typealias
1 parent cfbeca9 commit 1b156e7

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

Python/codegen.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,7 @@ codegen_setup_annotations_scope(compiler *c, location loc,
664664
codegen_enter_scope(c, name, COMPILE_SCOPE_ANNOTATIONS,
665665
key, loc.lineno, NULL, &umd));
666666

667-
// Insert None into consts to prevent an annotation
668-
// appearing to be a docstring
669-
_PyCompile_AddConst(c, Py_None);
667+
assert(!SYMTABLE_ENTRY(c)->ste_has_docstring);
670668
// if .format != 1: raise NotImplementedError
671669
_Py_DECLARE_STR(format, ".format");
672670
ADDOP_I(c, loc, LOAD_FAST, 0);
@@ -1592,9 +1590,8 @@ codegen_typealias_body(compiler *c, stmt_ty s)
15921590
ADDOP_LOAD_CONST_NEW(c, loc, defaults);
15931591
RETURN_IF_ERROR(
15941592
codegen_setup_annotations_scope(c, LOC(s), s, name));
1595-
/* Make None the first constant, so the evaluate function can't have a
1596-
docstring. */
1597-
RETURN_IF_ERROR(_PyCompile_AddConst(c, Py_None));
1593+
1594+
assert(!SYMTABLE_ENTRY(c)->ste_has_docstring);
15981595
VISIT_IN_SCOPE(c, expr, s->v.TypeAlias.value);
15991596
ADDOP_IN_SCOPE(c, loc, RETURN_VALUE);
16001597
PyCodeObject *co = _PyCompile_OptimizeAndAssemble(c, 0);
@@ -1890,9 +1887,7 @@ codegen_lambda(compiler *c, expr_ty e)
18901887
codegen_enter_scope(c, &_Py_STR(anon_lambda), COMPILE_SCOPE_LAMBDA,
18911888
(void *)e, e->lineno, NULL, &umd));
18921889

1893-
/* Make None the first constant, so the lambda can't have a
1894-
docstring. */
1895-
RETURN_IF_ERROR(_PyCompile_AddConst(c, Py_None));
1890+
assert(!SYMTABLE_ENTRY(c)->ste_has_docstring);
18961891

18971892
VISIT_IN_SCOPE(c, expr, e->v.Lambda.body);
18981893
if (SYMTABLE_ENTRY(c)->ste_generator) {

0 commit comments

Comments
 (0)