Correct traceback for multiline chain of method calling

Cameron Simpson cs at cskk.id.au
Fri Jul 9 19:03:01 EDT 2021


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>


More information about the Python-list mailing list