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

Skip to content

Commit ea66c7c

Browse files
committed
Use INTRINSIC_SET_CLASS_DICT
1 parent d77c4fb commit ea66c7c

1 file changed

Lines changed: 16 additions & 20 deletions

File tree

Python/compile.c

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,15 +2197,6 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
21972197
ADDOP(c, loc, PUSH_NULL);
21982198
// We'll swap in the callable here later.
21992199
ADDOP_LOAD_CONST(c, loc, Py_None);
2200-
PySTEntryObject *ste = PySymtable_Lookup(c->c_st, (void *)typeparams);
2201-
if (ste == NULL) {
2202-
return ERROR;
2203-
}
2204-
is_typeparams_in_class = ste->ste_type_params_in_class;
2205-
if (is_typeparams_in_class) {
2206-
ADDOP(c, loc, LOAD_LOCALS);
2207-
}
2208-
Py_DECREF(ste);
22092200
}
22102201

22112202
funcflags = compiler_default_arguments(c, loc, args);
@@ -2287,15 +2278,14 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
22872278
RETURN_IF_ERROR(compiler_nameop(c, loc, &_Py_STR(type_params), Load));
22882279
ADDOP_I(c, loc, CALL_INTRINSIC_2, INTRINSIC_SET_FUNCTION_TYPE_PARAMS);
22892280

2290-
if (is_typeparams_in_class) {
2291-
c->u->u_metadata.u_argcount += 1;
2292-
}
22932281
if (funcflags & 0x02) {
22942282
c->u->u_metadata.u_argcount += 1;
22952283
}
22962284
if (funcflags & 0x01) {
22972285
c->u->u_metadata.u_argcount += 1;
22982286
}
2287+
// Must be before we exit the scope
2288+
int is_typeparams_in_class = c->u->u_ste->ste_type_params_in_class;
22992289
PyCodeObject *co = optimize_and_assemble(c, 0);
23002290
compiler_exit_scope(c);
23012291
if (co == NULL) {
@@ -2306,6 +2296,10 @@ compiler_function(struct compiler *c, stmt_ty s, int is_async)
23062296
return ERROR;
23072297
}
23082298
Py_DECREF(co);
2299+
if (is_typeparams_in_class) {
2300+
ADDOP(c, loc, LOAD_LOCALS);
2301+
ADDOP_I(c, loc, CALL_INTRINSIC_2, INTRINSIC_SET_CLASS_DICT);
2302+
}
23092303
ADDOP_I(c, loc, SWAP, num_typeparam_args + 2);
23102304
ADDOP(c, loc, POP_TOP);
23112305
ADDOP_I(c, loc, CALL, num_typeparam_args);
@@ -2478,8 +2472,8 @@ compiler_class(struct compiler *c, stmt_ty s)
24782472
bases,
24792473
s->v.ClassDef.keywords));
24802474

2481-
int is_in_class = c->u->u_ste->ste_type_params_in_class;
2482-
c->u->u_metadata.u_argcount = is_in_class;
2475+
// Must be before we exit the scope
2476+
int is_typeparams_in_class = c->u->u_ste->ste_type_params_in_class;
24832477
PyCodeObject *co = optimize_and_assemble(c, 0);
24842478
compiler_exit_scope(c);
24852479
if (co == NULL) {
@@ -2490,10 +2484,11 @@ compiler_class(struct compiler *c, stmt_ty s)
24902484
return ERROR;
24912485
}
24922486
Py_DECREF(co);
2493-
if (is_in_class) {
2487+
if (is_typeparams_in_class) {
24942488
ADDOP(c, loc, LOAD_LOCALS);
2489+
ADDOP_I(c, loc, CALL_INTRINSIC_2, INTRINSIC_SET_CLASS_DICT);
24952490
}
2496-
ADDOP_I(c, loc, CALL, is_in_class);
2491+
ADDOP_I(c, loc, CALL, 0);
24972492
} else {
24982493
RETURN_IF_ERROR(compiler_call_helper(c, loc, 2,
24992494
s->v.ClassDef.bases,
@@ -2554,8 +2549,8 @@ compiler_typealias(struct compiler *c, stmt_ty s)
25542549
ADDOP_I(c, loc, BUILD_TUPLE, 3);
25552550
ADDOP_I(c, loc, CALL_INTRINSIC_1, INTRINSIC_TYPEALIAS);
25562551
if (asdl_seq_LEN(typeparams) > 0) {
2557-
int is_in_class = c->u->u_ste->ste_type_params_in_class;
2558-
c->u->u_metadata.u_argcount = is_in_class;
2552+
// Must be before we exit the scope
2553+
int is_typeparams_in_class = c->u->u_ste->ste_type_params_in_class;
25592554
PyCodeObject *co = optimize_and_assemble(c, 0);
25602555
compiler_exit_scope(c);
25612556
if (co == NULL) {
@@ -2566,10 +2561,11 @@ compiler_typealias(struct compiler *c, stmt_ty s)
25662561
return ERROR;
25672562
}
25682563
Py_DECREF(co);
2569-
if (is_in_class) {
2564+
if (is_typeparams_in_class) {
25702565
ADDOP(c, loc, LOAD_LOCALS);
2566+
ADDOP_I(c, loc, CALL_INTRINSIC_2, INTRINSIC_SET_CLASS_DICT);
25712567
}
2572-
ADDOP_I(c, loc, CALL, is_in_class);
2568+
ADDOP_I(c, loc, CALL, 0);
25732569
}
25742570
RETURN_IF_ERROR(compiler_nameop(c, loc, name, Store));
25752571
return SUCCESS;

0 commit comments

Comments
 (0)