QUERY · ISSUE
`tuple + class MyTuple(tuple)` performs a wrong type cast
py-core
class MyTuple(tuple):
pass
print((1,2) + MyTuple((3,4))) # prints (1, 2, (nil))
Relevant code:
https://github.com/micropython/micropython/blob/3b950ed2959c603ff30dd6052c157e7981c4d2d6/py/objtuple.c#L145-L153
mp_obj_tuple_binary_op checks rhs with mp_obj_is_subclass_fast and then casts it to mp_obj_tuple_t
CANDIDATE · PULL REQUEST
py: Simplify tuple subclass equality testing
py-core
This removes code that handles tuple-subclass equality test.
Since commit 3aab54bf434e7f025a91ea05052f1bac439fad8c this piece of code is no longer needed because the top-level function mp_obj_equal_not_equal() now handles the case of user types, and will never call tuple's binary_op function with MP_BINARY_OP_EQUAL and a non-tuple on the RHS.
Tests are added for additional coverage of related parts of this function.
@nickovs FYI, looks to be another little win for the improved equality testing.