Skip to content

NameError when using lambda function in a list comprehension in the interactive debugger under Python 3 #1037

@alexwlchan

Description

@alexwlchan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions