I’ve encountered a weird edge case around lambda functions in list comprehensions in the interactive debugger. I set up a function in the debugger as follows:
>>> f = lambda x: x
>>> f
<function <lambda> at 0x1068752a8>
>>> f(1)
1
>>> [f(x) for x in (1, 2, 3)]
If I run this code in Python 2.7.10, the output is exactly what you’d expected:
>>> [f(x) for x in (1, 2, 3)]
[1, 2, 3]
But if I run the same line in Python 3.5.0, I get a NameError:
>>> [f(x) for x in (1, 2, 3)]
Traceback (most recent call last):
File "<debugger>", line 1, in <module>
[f(x) for x in (1, 2, 3)]
File "<debugger>", line 1, in <listcomp>
[f(x) for x in (1, 2, 3)]
NameError: name 'f' is not defined
I’m running Werkzeug 0.11.11 on macOS 10.11.6. Each time I’m using a clean virtualenv, and using a minimal Flask app that drops straight into the interactive debugger.
I can reproduce the issue if I install from master at f34b02b.
I have a few other issues with defining functions in Python 3 in the interactive debugger, which might be related – I’ll raise as a separate issue.