classification
Title: Stacktrace identifies wrong line in multiline list comprehension
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.4, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Tracebacks should contain the first line of continuation lines
View: 12458
Assigned To: Nosy List: SMRUTI RANJAN SAHOO, ers81239, r.david.murray
Priority: normal Keywords:

Created on 2015-03-17 13:44 by ers81239, last changed 2015-03-21 04:31 by r.david.murray. This issue is now closed.

Messages (2)
msg238290 - (view) Author: Edward (ers81239) Date: 2015-03-17 13:44
This code:

z = [
        ["Y" for y in None
        ] for x in range(4)
    ]

produces this stacktrace in both Python 2.7 and 3.4:

Traceback (most recent call last):
  File "/Users/edwsmith/dev/untitled4/test.py", line 7, in <module>
    ] for x in range(4)
  File "/Users/edwsmith/dev/untitled4/test.py", line 7, in <listcomp>
    ] for x in range(4)
TypeError: 'NoneType' object is not iterable

Of course my code was slightly more complex, but I lost a fair amount of time troubleshooting how the 'for x in range(4)' was evaluating to None, when really, it was the inner comprehension that was failing.

Ideally the stack trace would say:

Traceback (most recent call last):
  File "/Users/edwsmith/dev/untitled4/test.py", line 6, in <module>
    ["Y" for y in None
  File "/Users/edwsmith/dev/untitled4/test.py", line 6, in <listcomp>
    ["Y" for y in None
TypeError: 'NoneType' object is not iterable
msg238438 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-03-18 13:38
This is a specific case of the more general problem discussed in issue 12458.
History
Date User Action Args
2015-03-21 04:31:47r.david.murraysetmessages: - msg238746
2015-03-21 04:31:32r.david.murraysetfiles: - py2.JPG
2015-03-21 01:57:09SMRUTI RANJAN SAHOOsetfiles: + py2.JPG
nosy: + SMRUTI RANJAN SAHOO
messages: + msg238746

2015-03-18 13:38:38r.david.murraysetstatus: open -> closed

superseder: Tracebacks should contain the first line of continuation lines

nosy: + r.david.murray
messages: + msg238438
resolution: duplicate
stage: resolved
2015-03-17 13:44:45ers81239create