[Python-ideas] Generator syntax hooks?

Soni L. fakedme+py at gmail.com
Mon Aug 7 15:30:05 EDT 2017


The generator syntax, (x for x in i if c), currently always creates a 
new generator. I find this quite inefficient:

{x for x in integers if 1000 <= x < 1000000} # never completes, because 
it's trying to iterate over all integers

What if, somehow, object `integers` could hook the generator and produce 
the equivalent of {x for x in range(1000, 1000000)}, which does complete?

What if, (x for x in integers if 1000 <= x < 1000000), was syntax sugar 
for (x for x in range(1000, 1000000))?

(I like mathy syntax. Do you like mathy syntax?)


More information about the Python-ideas mailing list