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.

Title: Partial implementation of generator comprehensions
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: jepler, rhettinger
Priority: normal Keywords: patch

Created on 2003-08-27 12:48 by jepler, last changed 2022-04-10 16:10 by admin. This issue is now closed.

File name Uploaded Description Edit
gencomp.patch jepler, 2003-08-27 12:48 Patch to compiler module
Messages (2)
msg44521 - (view) Author: Jeff Epler (jepler) Date: 2003-08-27 12:48

Recently, Generator Comprehensions were mentioned again
on python-list.
I have written an implementation for the compiler
module.  To try it
out, however, you must be able to rebuild Python from
source, because it
also requires a change to Grammar.

1. Edit Python-2.3/Grammar/Grammar and add an
alternative to the
"listmaker" production:
-listmaker: test ( list_for | (',' test)* [','] )
+listmaker: test ( list_for | (',' test)* [','] ) |
'yield' test list_for

1.5. Now [yield None for x in []] parses, but crashes
the written-in-C
    >>> [yield None for x in []]
    SystemError: com_node: unexpected node type

2. Apply the patch below to Lib/compiler

3. Use compiler.compile to compile code with generator
    from compiler import compile
    import dis

    code = compile("""
    def f():
            gg = [yield (x,y) for x in range(10) for y
in range(10) if y > x]
            print gg, type(gg), list(gg)
    """, "<None>", "exec")
    exec code

4. It's possible to write code so that __import__ uses
instead of the written-in-C compiler, but I don't have
this code handy.
Also, a test suite is needed, and presumably a
written-in-C implementation
as well. (option 2: make the compiler.compile interface
the standard
compiler, and let the builtin compiler support a Python
sufficient to bootstrap the written-in-python compiler,
or arrange
to ship .pyc of the compiler package and completely get
rid of the
written-in-C compiler)
msg44522 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-08-30 23:52
Logged In: YES 

Since the pep has been rejected, am closing the patch.
But will create a link to it from the PEP (note, the patch stays 
on the record even after it is closed).
Date User Action Args
2022-04-10 16:10:52adminsetgithub: 39136
2003-08-27 12:48:29jeplercreate