@@ -4237,18 +4237,20 @@ is_import_originated(struct compiler *c, expr_ty e)
42374237}
42384238
42394239static int
4240- can_optimize_super_call (struct compiler * c , expr_ty e )
4240+ can_optimize_super_call (struct compiler * c , expr_ty attr )
42414241{
4242+ expr_ty e = attr -> v .Attribute .value ;
42424243 if (e -> kind != Call_kind ||
42434244 e -> v .Call .func -> kind != Name_kind ||
42444245 !_PyUnicode_EqualToASCIIString (e -> v .Call .func -> v .Name .id , "super" ) ||
4246+ _PyUnicode_EqualToASCIIString (attr -> v .Attribute .attr , "__class__" ) ||
42454247 asdl_seq_LEN (e -> v .Call .keywords ) != 0 ) {
42464248 return 0 ;
42474249 }
42484250 Py_ssize_t num_args = asdl_seq_LEN (e -> v .Call .args );
42494251
42504252 PyObject * super_name = e -> v .Call .func -> v .Name .id ;
4251- // try to detect statically-visible shadowing of 'super' name
4253+ // detect statically-visible shadowing of 'super' name
42524254 int scope = _PyST_GetScope (c -> u -> u_ste , super_name );
42534255 if (scope != GLOBAL_IMPLICIT ) {
42544256 return 0 ;
@@ -4388,7 +4390,7 @@ maybe_optimize_method_call(struct compiler *c, expr_ty e)
43884390 /* Alright, we can optimize the code. */
43894391 location loc = LOC (meth );
43904392
4391- if (can_optimize_super_call (c , meth -> v . Attribute . value )) {
4393+ if (can_optimize_super_call (c , meth )) {
43924394 RETURN_IF_ERROR (load_args_for_super (c , meth -> v .Attribute .value ));
43934395 int opcode = asdl_seq_LEN (meth -> v .Attribute .value -> v .Call .args ) ?
43944396 LOAD_SUPER_METHOD : LOAD_ZERO_SUPER_METHOD ;
@@ -5406,7 +5408,7 @@ compiler_visit_expr1(struct compiler *c, expr_ty e)
54065408 return compiler_formatted_value (c , e );
54075409 /* The following exprs can be assignment targets. */
54085410 case Attribute_kind :
5409- if (e -> v .Attribute .ctx == Load && can_optimize_super_call (c , e -> v . Attribute . value )) {
5411+ if (e -> v .Attribute .ctx == Load && can_optimize_super_call (c , e )) {
54105412 RETURN_IF_ERROR (load_args_for_super (c , e -> v .Attribute .value ));
54115413 int opcode = asdl_seq_LEN (e -> v .Attribute .value -> v .Call .args ) ?
54125414 LOAD_SUPER_ATTR : LOAD_ZERO_SUPER_ATTR ;
0 commit comments