← index #5376Issue #4260
Off-topic · high · value 0.106
QUERY · ISSUE

Empty op name printed when missing from mp_binary_op_method_name

openby Jongyopened 2019-12-04updated 2019-12-04
py-core

With MICROPY_PY_ALL_SPECIAL_METHODS =0,

>>> 1 + 1
2
>>> 1 + 1 / 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported types for  : 'int', 'int'
>>> 

You can see the print is a bit broken and it makes you question whether something deeper has gone wrong. I think it would be better to print something, like "unknown" or "unknown op".

For example, [0 ... MP_BINARY_OP_NUM_RUNTIME-1] = MP_QSTR_unknown, as the first line of mp_binary_op_method_name does the trick. It basically adds just this single "unknown" qstr.

CANDIDATE · ISSUE

`OverflowError` sometimes doesn't create traceback data

openby dhalbertopened 2018-10-21updated 2018-10-22

In some cases, OverflowError will not print traceback data. This is apparently because mp_obj_exception_add_traceback() never gets called in py/vm.c. I set a breakpoint there and it didn't get called. I'm not sure if this is deliberate or not. (Is it some VM fast path shortcut or something?)

To reproduce, use the minimal Unix port.

$ ./micropython_minimal 
MicroPython v1.9.4-665-g7795b2e5c on 2018-10-21; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> 10000000000000000000000000000000             # NO traceback
OverflowError: long int not supported in this build 
>>> 2**63 * 2**63                                # has traceback
Traceback (most recent call last):
  File "<stdin>", in <module>
OverflowError: small int overflow
>>> 2**65                                        # has traceback
Traceback (most recent call last):
  File "<stdin>", in <module>
OverflowError: small int overflow 
>>> 999999999999999999 * 999999999999999999      # NO traceback
OverflowError: small int overflow
>>> 3//0                         # ZeroDivisionError does have traceback
Traceback (most recent call last):
  File "<stdin>", in <module>
ZeroDivisionError: divide by zero
>>>  

(This was noticed by a CircuitPython user in our small non-longint builds: https://github.com/adafruit/circuitpython/issues/1269)

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