My (late) beef with Simple Generator syntax (PEP 255)

Greg Ewing see_reply_address at something.invalid
Sun Nov 17 21:30:43 EST 2002


Alan Kennedy wrote:
 >

> class emptyGenerator:
> 
>     def __init__(self):
>         raise StopIteration()
> 
> def emptyGen():
>     yield emptyGenerator()


This is quite nice, but it's misnamed slightly.
Something called xxxGenerator should be returning
an iterator when you call it, but this isn't.

It would be nicer if it were called Nothing.
Then you could write

   def emptyGen():
      yield Nothing()

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list