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

Alan Kennedy alanmk at hotmail.com
Tue Nov 19 06:50:41 EST 2002


Alan wrote:

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

Greg wrote:

> 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()


While I agree that it was badly named, on thinking further about it, I'm
not sure that "nothing" (i.e. "no thing") is the right name. The right
name is "no thingS". So that would be

class noThings:
    def __init__(self):
        raise StopIteration()

def emptyGen:
    yield noThings()

hair-splitting-ly yrs :-)

-- 
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan:              http://xhaus.com/mailto/alan



More information about the Python-list mailing list