Correct traceback for multiline chain of method calling
Peter Otten
__peter__ at web.de
Sat Jul 10 03:20:08 EDT 2021
On 09/07/2021 17:29, Артем Комендантян wrote:
> Hello!
>
> 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.
>
> I propose to have a line with the method name in traceback if this method
> fails.
>
> 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?
If I understand you correctly there's hope; the upcoming Python 3.10
will show the failing method call:
Python 3.10.0b3 (tags/v3.10.0b3:865714a, Jun 17 2021, 20:19:11) [MSC
v.1929 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
class A:
def chain(self): return self
def fail(self): 1/0
(A()
.chain()
.chain()
.fail()
.chain()
)
Traceback (most recent call last):
File "<pyshell#9>", line 4, in <module>
.fail()
File "<pyshell#3>", line 3, in fail
def fail(self): 1/0
ZeroDivisionError: division by zero
More information about the Python-list
mailing list