Dear Ideas,

TL;DR include multiple lines in traceback when appropriate (expressions
broken up over multiple lines) to make it easier to spot error from looking
at traceback

Apologies if this has been suggested/discussed before. I am suggesting that
if you do:

```
[
    x for x in 0
]
```

the traceback will be:

```
Traceback (most recent call last):
  File "foo.py", line 1-3, in <module>
    [
        x for x in 0
    ]
TypeError: 'int' object is not iterable
```

instead of the current

```
Traceback (most recent call last):
  File "foo.py", line 1, in <module>
    [
TypeError: 'int' object is not iterable
```

Similarly for when an operator is applied over different lines:

```
(
   0 &
   "world"
)
```

would lead to
```
Traceback (most recent call last):
  File "foo.py", line 2-3, in <module>
    0 &
    "world"
TypeError: unsupported operand type(s) for &: 'int' and 'str'
```

instead of

```
Traceback (most recent call last):
  File "foo.py", line 2-3, in <module>
    "hello" &
TypeError: unsupported operand type(s) for &: 'int' and 'str'
```

Or when an open has been split over multiple lines (note missing comma):

```
open(
    "foo"
    "r"
)
```

to be

```
Traceback (most recent call last):
  File "foo.py", line 1-4, in <module>
    open(
        "foo"
        "r"
    )
FileNotFoundError: [Errno 2] No such file or directory: 'foor'
```

instead of

```
Traceback (most recent call last):
  File "foo.py", line 1-3, in <module>
    open(
FileNotFoundError: [Errno 2] No such file or directory: 'foor'
```

I don't think this change would rock the world, but I think it is a nice
quality-of-life improvement that would ease debugging. In particular the
last example (open function call) showcases how it can make easier to spot
a bug, especially if it is to do with how the expression is broken up

What do people think? Any particular reason this is not possible or done?
I'm guessing it would require quite a bit of restructuring in the traceback
object/module and potentially have backwards compatibility implications.

All the best,

Henk-Jaap
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/SKA4JZGYOSRJVCHH6Y2CA2MDIX3MMPZA/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to