This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients
Date 2004-05-20.17:08:00
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=80475

Jiwon, while working through the doc patch, I noticed a code
generation nit.  The code g=(i for i in range(10)) gets
translated to:

def __gen(exp):
   for i in exp:
       yield i
g = __gen(iter(range(10))
del __gen

On the next to last line, the call to iter() may be
superfluous.  Do 
you see a need for it?  If so, I need to include that in the
spec.  If not, then it should be removed (line 1822 in
compile.c).

In terms of byte codes, the difference shows up in a
comparison to an equivalent generator:

>>> dis(compile('g(range(10))', '', 'eval'))
  0           0 LOAD_NAME                0 (g)
              3 LOAD_NAME                1 (range)
              6 LOAD_CONST               0 (10)
              9 CALL_FUNCTION            1
             12 CALL_FUNCTION            1
             15 RETURN_VALUE 
       
>>> dis(compile('(i for i in range(10))', '', 'eval'))
  0           0 LOAD_CONST               0 (<code object
<generator expression> at 00A4B220, file "", line 1>)
              3 MAKE_FUNCTION            0
              6 LOAD_NAME                0 (range)
              9 LOAD_CONST               1 (10)
             12 CALL_FUNCTION            1
             15 GET_ITER            
             16 CALL_FUNCTION            1
             19 RETURN_VALUE  

The get_iter at code position 15 is what is in question.

History
Date User Action Args
2007-08-23 15:31:41adminlinkissue872326 messages
2007-08-23 15:31:41admincreate