[Python-Dev] Naming comprehension syntax [was Re: Informal educator feedback on PEP 572 ...]

Steven D'Aprano steve at pearwood.info
Fri Jul 6 22:13:45 EDT 2018

On Sat, Jul 07, 2018 at 02:58:23AM +0300, Ivan Pozdeev via Python-Dev wrote:

> >Also, "generator builder" is not much more expressive than "generator 
> >expression",

I agree with Guido on that comment. The only advantage (such little as 
it is) is that we can refer to them all using the same terminology:

    [list | set | dict | generator] builder syntax

but given how prevalent the comprehension terminology has become, maybe 
the best we can hope for is to start using "generator comprehension".

> "generator builder" is simply incorrect. The GE doesn't "build" 
> generators, it's a generator itself.

Nobody suggested that it was an thing that you call to build a 
generator. The name refers to the syntax, not the object. I did refer to 
it as *generator builder syntax* in my earlier post, and explicitly 
noted that "list/set/dict/generator builder" was the abbreviated form.

But as Guido says, the possible confusion with the Builder design 
pattern makes this terminology confusing. If we were back in Python 2.2 
days when neither the feature nor the terminology "comprehension" were 
so well established, perhaps we could have gone with "builder" instead, 
but I think that ship has sailed.

> It's a generator _and_ an 
> expression. What could be a more obvious name?

It's not about the obviousness, it is about it being a mouthful to say 
"comprehension or generator expression" to represent something which is 
conceptually a single kind of thing.

We can use "comprehension" to group "list comprehension or dict 
comprehension or dict comprehension", but generator expressions are the 
odd one out.

> This suggestion looks like coming from someone who hasn't quite grasped 
> generators yet.

I assure you that both Greg and I understand generators quite well.


More information about the Python-Dev mailing list