Skip to content

Commit e4466a7

Browse files
committed
simplify oparg & 2 handling
1 parent 3a3cb74 commit e4466a7

File tree

4 files changed

+232
-241
lines changed

4 files changed

+232
-241
lines changed

Doc/library/dis.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1048,8 +1048,8 @@ iterations of the loop.
10481048
The low bit of ``namei`` signals to attempt a method load, as with
10491049
:opcode:`LOAD_ATTR`.
10501050

1051-
The second-low bit of ``namei``, if set, means that this was a zero-argument
1052-
call to :func:`super`.
1051+
The second-low bit of ``namei``, if set, means that this was a two-argument
1052+
call to :func:`super` (unset means zero-argument).
10531053

10541054
.. versionadded:: 3.12
10551055

Python/bytecodes.c

+2-7
Original file line numberDiff line numberDiff line change
@@ -1574,13 +1574,8 @@ dummy_func(
15741574
Py_DECREF(self);
15751575
}
15761576
} else {
1577-
PyObject *super;
1578-
if (oparg & 2) {
1579-
super = PyObject_CallNoArgs(global_super);
1580-
} else {
1581-
PyObject *stack[] = {class, self};
1582-
super = PyObject_Vectorcall(global_super, stack, 2, NULL);
1583-
}
1577+
PyObject *stack[] = {class, self};
1578+
PyObject *super = PyObject_Vectorcall(global_super, stack, oparg & 2, NULL);
15841579
DECREF_INPUTS();
15851580
ERROR_IF(super == NULL, error);
15861581
res = PyObject_GetAttr(super, name);

Python/compile.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1053,21 +1053,21 @@ compiler_addop_name(struct compiler_unit *u, location loc,
10531053
}
10541054
if (opcode == LOAD_SUPER_ATTR) {
10551055
arg <<= 2;
1056+
arg |= 2;
10561057
}
10571058
if (opcode == LOAD_SUPER_METHOD) {
10581059
opcode = LOAD_SUPER_ATTR;
10591060
arg <<= 2;
1060-
arg |= 1;
1061+
arg |= 3;
10611062
}
10621063
if (opcode == LOAD_ZERO_SUPER_ATTR) {
10631064
opcode = LOAD_SUPER_ATTR;
10641065
arg <<= 2;
1065-
arg |= 2;
10661066
}
10671067
if (opcode == LOAD_ZERO_SUPER_METHOD) {
10681068
opcode = LOAD_SUPER_ATTR;
10691069
arg <<= 2;
1070-
arg |= 3;
1070+
arg |= 1;
10711071
}
10721072
return codegen_addop_i(&u->u_instr_sequence, opcode, arg, loc);
10731073
}

0 commit comments

Comments
 (0)