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

Terry Reedy tjreedy at udel.edu
Sat Jul 7 01:19:33 EDT 2018

On 7/6/2018 7:31 PM, Guido van Rossum wrote:
> On Fri, Jul 6, 2018 at 4:19 PM Terry Reedy <tjreedy at udel.edu 
> <mailto:tjreedy at udel.edu>> wrote:
>     Since Guido, the first respondent, did not immediately shoot the idea
>     down, I intend to flesh it out and make it more concrete.
> Maybe I should have shot it down.

I glad you did not do so immediately since some of what I worked out 
since applies to the alternative of consistently using 'comprehension'.

> The term is entrenched in multiple 
> languages by now (e.g. 
> https://en.wikipedia.org/wiki/List_comprehension). Regarding "list 
> builder" one could argue that it would just add more confusion, since 
> there's already an unrelated Builder Pattern 

I was not aware of that.  I read enough to see that as a relevant conflict.

> (https://en.wikipedia.org/wiki/Builder_pattern) commonly used in Java. 
> (Though I worry about the presence of a Python example in that Wikipedia 
> page. :-)
> Also, "generator builder" is not much more expressive than "generator 
> expression",

If one views 'generator expression' as a 2-word phrase, as opposed to a 
defined compound word, it could mean either 'expression that contains a 
generator' or 'expression that evaluates to a generator.  With the 
latter meaning, 'generator_func(*args)' is a generator expression.  I 
intended 'generator builder' to be more clearly delimited.  So is 
'generator comprehension'.

> and the key observation that led to this idea was that it's 
> such a mouthful to say "comprehensions and generator expressions".

That was part of my motivation also.

> Maybe it's not too late
> to start calling the latter "generator comprehensions" 

Having proposed a more drastic change, I obviously think it is not too 
late to change the doc at least for 3.8.  (If we do it now, I would 
consider 3.7 also.)  Rename the Expressions section to just 
'Comprehensions'.  Define 'comprehension' perhaps as "an expression that 
defines an iterable using Python's adaptation and generalization of 
extended set builder notation".  Comprehensions have to be fenced for 
use (except for gencomps in function calls) to determine the concrete 
type of iterable. The key:value syntax that separates dict from set 
displays separates dict from set comprehensions.

Otherwise: Change to 'generator comprehension'.  Do whatever to the doc 
grammar.  Adjust glossary entries.  If allowed in our reference format, 
perhaps link to Wikipedia articles on 'set builder notation' and 'list 

The 8 syllables of 'generator comprehension' is bit long for a compound 
word.  Python uses '<genexpr>' as the pseudo-name for generators.  Some 
people use 'genexp' as an abbreviation (do they pronounce the 'p'?), 
along with listcomp.  'Gencomp' should do as well.

> so that maybe by the year 2025 we can say "comprehensions" and everyone 
> will understand we mean all four types?
> FWIW more people should start using "list display" etc. for things like 
> [a, b, c].


Terry Jan Reedy

More information about the Python-Dev mailing list