[Patches] [ python-Patches-1167628 ] [AST] Generator expressions

SourceForge.net noreply at sourceforge.net
Tue Mar 22 09:37:19 CET 2005


Patches item #1167628, was opened at 2005-03-22 00:45
Message generated for change (Comment added) made by ncoghlan
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1167628&group_id=5470

Category: Core (C code)
Group: AST
Status: Open
Resolution: None
Priority: 5
Submitted By: Nick Coghlan (ncoghlan)
Assigned to: Brett Cannon (bcannon)
Summary: [AST] Generator expressions

Initial Comment:
Adds generator expression support to the AST branch. 
Support is sufficient to allow test_grammar to pass. 
 
Also eliminates the display of interim results within functions 
compiled at the interactive prompt, and the allocation of large 
amounts of memory when zero is passed to asdl_seq_new. 

----------------------------------------------------------------------

>Comment By: Nick Coghlan (ncoghlan)
Date: 2005-03-22 18:37

Message:
Logged In: YES 
user_id=1038590

Correcting a previous comment: the check that ensures an 
unparenthesised generator expression is a sole argument is in 
ast_for_call. 

----------------------------------------------------------------------

Comment By: Nick Coghlan (ncoghlan)
Date: 2005-03-22 14:04

Message:
Logged In: YES 
user_id=1038590

Updated patch ast_genexp_2.diff which correctly allows generator 
expressions to be part of a testlist_gexp node or an argument node. 
 
Removed old patch which failed for debug builds. 

----------------------------------------------------------------------

Comment By: Nick Coghlan (ncoghlan)
Date: 2005-03-22 13:42

Message:
Logged In: YES 
user_id=1038590

I'm actually wondering if the grammar is entirely correct
here. Really, what is allowed for an argument is:

argument: test [gen_for | ('=' test)]

But that still permits generator expressions that are not
the sole argument. So I'd be tempted to move the 'gen_for'
up to the arglist level:

arglist: (test gen_for) | ((argument ',')* (argument [','] |
'*' test [',' '**' test] |  '**' test))
argument: test ['=' test]

As it is, I simply have a check in ast_gen_exp which imposes
the above rule (i.e. a generator expression as an argument
must be the sole argument, or parenthesised so that it
becomes a 'test' node in its own right)

----------------------------------------------------------------------

Comment By: Nick Coghlan (ncoghlan)
Date: 2005-03-22 13:22

Message:
Logged In: YES 
user_id=1038590

I did wonder about that, but the assert wasn't triggering
for me. The offending line is REQ(n, testlist_gexpr) in
ast_for_genexp.

I'll setup a debug build to check all of the assertions
properly.

----------------------------------------------------------------------

Comment By: John Ehresman (jpe)
Date: 2005-03-22 04:02

Message:
Logged In: YES 
user_id=22785

This triggers an assert with a genexp in an argument because
the node is not a testlist_gexp, e.g. foo(i for i in
range(5)).  It's unclear what to do with foo(a = i for i in
range(5); see bug # 1167751

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1167628&group_id=5470


More information about the Patches mailing list