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

Skip to content

Commit 2e913ca

Browse files
committed
Same for type aliases
1 parent b314a3f commit 2e913ca

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

Python/compile.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,6 +2540,7 @@ compiler_typealias(struct compiler *c, stmt_ty s)
25402540
RETURN_IF_ERROR(compiler_add_const(c->c_const_cache, c->u, Py_None));
25412541
VISIT_IN_SCOPE(c, expr, s->v.TypeAlias.value);
25422542
ADDOP_IN_SCOPE(c, loc, RETURN_VALUE);
2543+
int is_in_class = c->u->u_ste->ste_type_params_in_class;
25432544
PyCodeObject *co = optimize_and_assemble(c, 1);
25442545
compiler_exit_scope(c);
25452546
if (co == NULL) {
@@ -2550,6 +2551,10 @@ compiler_typealias(struct compiler *c, stmt_ty s)
25502551
return ERROR;
25512552
}
25522553
Py_DECREF(co);
2554+
if (is_in_class) {
2555+
ADDOP(c, loc, LOAD_LOCALS);
2556+
ADDOP_I(c, loc, CALL_INTRINSIC_2, INTRINSIC_SET_CLASS_DICT);
2557+
}
25532558
ADDOP_I(c, loc, BUILD_TUPLE, 3);
25542559
ADDOP_I(c, loc, CALL_INTRINSIC_1, INTRINSIC_TYPEALIAS);
25552560
if (asdl_seq_LEN(typeparams) > 0) {

Python/symtable.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
13991399
VISIT(st, expr, s->v.TypeAlias.name);
14001400
assert(s->v.TypeAlias.name->kind == Name_kind);
14011401
PyObject *name = s->v.TypeAlias.name->v.Name.id;
1402+
int is_in_class = st->st_cur->ste_type == ClassBlock;
14021403
if (asdl_seq_LEN(s->v.TypeAlias.typeparams) > 0) {
14031404
if (!symtable_enter_typeparam_block(
14041405
st, name,
@@ -1412,6 +1413,7 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
14121413
if (!symtable_enter_block(st, name, TypeAliasBlock,
14131414
(void *)s, LOCATION(s)))
14141415
VISIT_QUIT(st, 0);
1416+
st->st_cur->ste_type_params_in_class = is_in_class;
14151417
VISIT(st, expr, s->v.TypeAlias.value);
14161418
if (!symtable_exit_block(st))
14171419
VISIT_QUIT(st, 0);

0 commit comments

Comments
 (0)