Missing MP_BINARY_OP_REVERSE_LESS etc.
Port, board and/or hardware
Windows
MicroPython version
3.4.0; MicroPython 674a124bbe-dirty on 2026-01-01
Reproduction
from ulab import numpy as np
print(3 < np.array([1,2,3,4]))
Expected behaviour
[False False False True]
Observed behaviour
TypeError: unsupported types for lt: 'int', 'ndarray'
Additional Information
Here're the required changes for the fix:
-
Add to 'mp_binary_op_t' on runtime0.h
MP_BINARY_OP_REVERSE_LESS,
MP_BINARY_OP_REVERSE_MORE,
MP_BINARY_OP_REVERSE_EQUAL,
MP_BINARY_OP_REVERSE_LESS_EQUAL,
MP_BINARY_OP_REVERSE_MORE_EQUAL,
MP_BINARY_OP_REVERSE_NOT_EQUAL, -
Add the following code:
if (op >= MP_BINARY_OP_LESS && op <= MP_BINARY_OP_NOT_EQUAL) {
mp_obj_t t = rhs;
rhs = lhs;
lhs = t;
op += MP_BINARY_OP_REVERSE_LESS - MP_BINARY_OP_LESS;
goto generic_binary_op;
} else if (op >= MP_BINARY_OP_OR && op <= MP_BINARY_OP_POWER) {
instead of the line "if (op >= MP_BINARY_OP_OR && op <= MP_BINARY_OP_POWER) {"
After these two changes I get the expected result with no error
Code of Conduct
Yes, I agree
binary_op_maybe: Path was missing nlr_pop call.
Summary
One of the constant folding paths in binary_op_maybe was missing a needed nlr_pop call.
Reproducer:
ans = (-1) ** 2.3
aa
Closes: #17815
Testing
I tested manually.
Trade-offs and Alternatives
I did not add a test for the issue.