[issue37647] Wrong lineno in traceback when formatting strings with % and multilines

Bruno P. Kinoshita report at bugs.python.org
Mon Jul 22 02:45:26 EDT 2019


Bruno P. Kinoshita <brunodepaulak at yahoo.com.br> added the comment:

Hi Ammar, thanks for the quick reply and for the suggestion.

Tried on the latest version on master, and looks like it's indeed different, though still looks like it is displaying the wrong line number.

```
kinow at localhost:~/Development/python/workspace/cpython$ python
Python 3.9.0a0 (heads/master:b530a4460b, Jul 22 2019, 18:38:44) 
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
kinow at localhost:~/Development/python/workspace/cpython$ python z.py
Traceback (most recent call last):
  File "/home/kinow/Development/python/workspace/cpython/z.py", line 14, in <module>
    print(list(raise_generator()))
  File "/home/kinow/Development/python/workspace/cpython/z.py", line 7, in raise_generator
    yield 'three values are: %s %s %s' % (
  File "/home/kinow/Development/python/workspace/cpython/z.py", line 3, in __str__
    raise ValueError('Z error')
ValueError: Z error
```

It is now displaying the line number 7, where the yield statement begins, instead of where it actually happened (line 9).

And once again, if I replace `Z()` by `Z().__str__()`, then it displays the right line number.

```
kinow at localhost:~/Development/python/workspace/cpython$ python z.py
Traceback (most recent call last):
  File "/home/kinow/Development/python/workspace/cpython/z.py", line 14, in <module>
    print(list(raise_generator()))
  File "/home/kinow/Development/python/workspace/cpython/z.py", line 9, in raise_generator
    Z().__str__(),  # traceback must point to this lineno 9
  File "/home/kinow/Development/python/workspace/cpython/z.py", line 3, in __str__
    raise ValueError('Z error')
ValueError: Z error
```

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37647>
_______________________________________


More information about the Python-bugs-list mailing list