[Python-Dev] Generator methods - "what's next" ?
Firephoenix
firephoenix at wanadoo.fr
Sun Apr 5 15:35:21 CEST 2009
Georg Brandl a écrit :
> Firephoenix schrieb:
>
>> Hello everyone
>>
>> I'm a little confused by the recent changes to the generator system...
>>
>> I basically agreed with renaming the next() method to __next__(), so as
>> to follow the naming of other similar methods (__iter__() etc.).
>> But I noticed then that all the other methods of the generator had
>> stayed the same (send, throw, close...), which gives really weird (imo)
>> codes :
>>
>> next(it)
>> it.send(35)
>> it.throw(Exception())
>> next(it)
>> ....
>>
>> Browsing the web, I've found people troubled by that asymmetry, but no
>> remarks on its causes nor its future...
>>
>> Since __next__(), send() and others have really really close semantics,
>> I consider that state as a python wart, one of the few real ones I can
>> think of.
>>
>
> You're missing an important detail: next()/__next__() is a feature of all
> iterators, while send() and throw() are generator-only methods.
>
> The only thing I could imagine is to add a generator.next() method that
> is simply an alias for generator.__next__(). However, TSBOOWTDI.
>
> cheers,
> Georg
>
>
Good point indeed.
Generator methods (send, throw...) are some kind of black magic compared
to normal methods, so I'd find it normal if their naming reflected this
specificity, but on the other end it wouldn't be cool to overflow the
builtin scope with all the corresponding functions "send(iter, var)"...
so I guess all that will stay the way it is.
Regards,
Pascal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20090405/1cfd6a82/attachment.htm>
More information about the Python-Dev
mailing list