← index #18626PR #17816
Off-topic · high · value 0.490
QUERY · ISSUE

Missing MP_BINARY_OP_REVERSE_LESS etc.

openby arnonsenopened 2026-01-01updated 2026-01-02
enhancementpy-core

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:

  1. 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,

  2. 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

CANDIDATE · PULL REQUEST

binary_op_maybe: Path was missing nlr_pop call.

closedby jepleropened 2025-08-02updated 2025-08-03
py-core

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.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied