I was learning cpython internals(especially the is
operator) and came across the following opcode implementation for IS_OP
in ceval.c
case TARGET(IS_OP): {
PyObject *right = POP();
PyObject *left = TOP();
int res = (left == right)^oparg;
PyObject *b = res ? Py_True : Py_False;
...
}
I know the first two statements pop the operands from the stack.
PyObject *right = POP();
PyObject *left = TOP();
But my question is related to the following statement.
int res = (left == right)^oparg;
In my understanding is
operator in python compares object identity, In other teams it will check whether both the objects are pointing to the same object. So my question is, only the following code is sufficient to check the object identity?, Why the actual implementation again apply an exlcusive OR(^
) with oparg
?
int res = (left == right)