py/parse: Remove explicit checks for invalid folding operations.

They are instead checked by `binary_op_maybe()`, which catches exceptions
for invalid int/float operations.

This is a follow-up to 69ead7d98e

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2025-08-11 14:44:48 +10:00
parent 141f7d0c35
commit 3efbd726eb

View File

@@ -771,12 +771,6 @@ static bool fold_constants(parser_t *parser, uint8_t rule_id, size_t num_args) {
if (!mp_parse_node_get_number_maybe(pn, &arg1)) {
return false;
}
#if !MICROPY_COMP_CONST_FLOAT
if (op == MP_BINARY_OP_POWER && mp_obj_int_sign(arg1) < 0) {
// ** can't have negative rhs
return false;
}
#endif
if (!binary_op_maybe(op, arg0, arg1, &arg0)) {
return false;
}
@@ -796,16 +790,6 @@ static bool fold_constants(parser_t *parser, uint8_t rule_id, size_t num_args) {
return false;
}
mp_token_kind_t tok = MP_PARSE_NODE_LEAF_ARG(peek_result(parser, i));
if (tok == MP_TOKEN_OP_AT) {
// Can't fold @
return false;
}
#if !MICROPY_COMP_CONST_FLOAT
if (tok == MP_TOKEN_OP_SLASH) {
// Can't fold /
return false;
}
#endif
mp_binary_op_t op = MP_BINARY_OP_LSHIFT + (tok - MP_TOKEN_OP_DBL_LESS);
if (!binary_op_maybe(op, arg0, arg1, &arg0)) {
return false;