[New-bugs-announce] [issue23687] Stacktrace identifies wrong line in multiline list comprehension

Edward report at bugs.python.org
Tue Mar 17 14:44:45 CET 2015


New submission from Edward:

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

----------
components: Interpreter Core
messages: 238290
nosy: ers81239
priority: normal
severity: normal
status: open
title: Stacktrace identifies wrong line in multiline list comprehension
type: behavior
versions: Python 2.7, Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23687>
_______________________________________


More information about the New-bugs-announce mailing list