[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Why won't the run-time error reporter point to the error position with a caret like the syntax error reporter does? It knows exactly where the error is.

On Thu, Aug 1, 2019 at 4:34 PM Terry Reedy <tjreedy at udel.edu> wrote:
> On 7/31/2019 11:19 PM, jsalsman at gmail.com wrote:
> > Honestly this is the only thing in over half a decade of daily python use which has disappointed me enough to want to ask the devs:
> >
> >>>> print(1/)
> >    File "<stdin>", line 1
> >      print(1/)
> >              ^
> > SyntaxError: invalid syntax
> SyntaxErrors mostly come from the parser, occasionally from the
> compiler, both of which have access to line and column.
> >>>> print(1/1, 1/0, 1/1)
> > Traceback (most recent call last):
> >    File "<stdin>", line 1, in <module>
> > ZeroDivisionError: division by zero
> This comes from the runtime engine, which only has access to line
> numbers, and even line numbers lie when a statement spans multiple
> lines.  In CPython, the runtime engine is executing bytecodes, and
> bytecode do not correspond to column numbers.  In something like
> "a + b / (2 * c + d//3)", if the denominator (which could be on multiple
> lines) is 0, where should a caret point?

Probably to the slash, since it's the division operation that threw
the error. I don't think it would be all that useful, but it would at
least be sane and logical.