A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-October/057175.html below:

[Python-Dev] problem with genexp

[Python-Dev] problem with genexp [Python-Dev] problem with genexpNeal Norwitz nnorwitz at gmail.com
Tue Oct 11 06:15:22 CEST 2005
There's a problem with genexp's that I think really needs to get
fixed.  See http://python.org/sf/1167751 the details are below.  This
code:

>>> foo(a = i for i in range(10))

generates "NameError: name 'i' is not defined" when run because:

2           0 LOAD_GLOBAL              0 (foo)
              3 LOAD_CONST               1 ('a')
              6 LOAD_GLOBAL              1 (i)
              9 CALL_FUNCTION          256
             12 POP_TOP
             13 LOAD_CONST               0 (None)
             16 RETURN_VALUE

If you add parens around the code:   foo(a = i for i in range(10))
You get something quite different:

2           0 LOAD_GLOBAL              0 (foo)
              3 LOAD_CONST               1 ('a')
              6 LOAD_CONST               2 (<code object <generator
expression> at 0x2a960baae8, file "<stdin>", line 2>)
              9 MAKE_FUNCTION            0
             12 LOAD_GLOBAL              1 (range)
             15 LOAD_CONST               3 (10)
             18 CALL_FUNCTION            1
             21 GET_ITER
             22 CALL_FUNCTION            1
             25 CALL_FUNCTION          256
             28 POP_TOP
             29 LOAD_CONST               0 (None)
             32 RETURN_VALUE

I agree with the bug report that the code should either raise a
SyntaxError or do the right thing.

n
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4