Correct traceback for multiline chain of method calling

Artem Komendantian komendantyan.artem at gmail.com
Fri Jul 9 21:28:25 EDT 2021


> That line is already there:

>    #   File "/home/komendart/temp/script.py", line 6, in fail
>    #     raise RuntimeError('fail')

Probably I should rewrite more concretely.
I have such traceback ending for python3.7
#   File "script.py", line 15, in main
#     .fail(True)
#   File "script.py", line 6, in fail
#     raise RuntimeError('fail')

It has the exact line of the failing method's call (line 15) and that is
what I want for fresh python in general.
Just the name of the method and place inside of it with error in the last
part of traceback is not enough because this method can occur in the chain
several times (like .fail in my simple example) and I want to get a line of
the exact call.

> Annoying, but it would provide the desired precision.
I agree with all parts of this sentence :) Well, I can live with such a
solution but it is really uncomfortable.

In python3.7 and lower (even in python2, lol) if a method was called with
some arguments traceback had a line corresponding to some argument of
needed call. This behaviour was suitable for me.

I can a bit formalize my suggestion to improve python tracebacks.
If we have code in one line like

(
(some complex construction of object with __call__)
(
some arguments
)
)

traceback should contain a line with opening brace before arguments (Now in
the last python traceback seems to contain the start of the called object's
construction)
The last line of called object's construction or first of arguments
enumerating is ok too, it doesn't really matter for me.

BTW it is not important for me but I can dream how this proposal can be
generalized. For example for failing index operations a[b] (error line must
be close to [ here) or for all binary operations (a + b fails => the error
line must be close to the line with plus operator).

Does it sound reasonable? Am I on the right mailing list for python
improvement suggestions? :)

--
Best wishes,
Artem Komendantian
komendantyan.artem at gmail.com


сб, 10 июл. 2021 г. в 02:53, Cameron Simpson <cs at cskk.id.au>:

> On 09Jul2021 18:29, Артем Комендантян <komendantyan.artem at gmail.com>
> wrote:
> >There is a code https://pastebin.com/0NLsHuLa.
> >It has a multiline chain of method calling, when some method fails. In
> >python3.7 it fails in a row which corresponds to the failing method, in
> >python3.9 it corresponds to the very first line.
> >
> >Another similar example is https://pastebin.com/2P9snnMn
> >The error is on the first line for older pythons too.
>
> Interesting.
>
> There was some work done in recent Pythons to improve syntax error
> reporting. I wonder if it has had side effects on the reporting.
>
> >I propose to have a line with the method name in traceback if this
> >method
> >fails.
>
> That line is already there:
>
>     #   File "/home/komendart/temp/script.py", line 6, in fail
>     #     raise RuntimeError('fail')
>
> See that it points at the fail() method from line 6 of the script?
>
> >I develop some library when it is very popular among users to declare some
> >operations with such multiline chains. Also I want to keep correct
> >traceback for each operation because the first line is not very
> informative
> >when some method occurred more than once in this chain.
> >
> >Can this improvement be done? Maybe anybody has any other suggestions on
> >how to get the correct line in traceback right now?
>
> Aside from putting the whole thing on 1 line? Joking.
>
> Possibly only by breaking it up purely while debugging:
>
>     x = a.do_nothing()
>     x = x.do_nothing()
>     x = x.fail(True)
>
> and so forth. Annoying, but it would providethe desired precision.
>
> Cheers,
> Cameron Simpson <cs at cskk.id.au>
> --
> https://mail.python.org/mailman/listinfo/python-list
>


More information about the Python-list mailing list