[Python-3000] callable()
Nick Coghlan
ncoghlan at gmail.com
Fri Jul 21 11:33:22 CEST 2006
Greg Ewing wrote:
> Guido van Rossum wrote:
>
>> Actually, the autowrapping was intended a backwards compatibility measure.
>
> But it seems like a perfectly good and useful feature
> in its own right to me. Why force every sequence to
> implement its own __iter__ if there is a default one
> that does the same as what your custom one would have
> done anyway?
The standard sequence iterator should still be somewhere in the standard
library (e.g. as itertools.seqiter). This could then be used by assigning it
as the __iter__ method in a class definition, or to a tp_iter slot through the
C API.
The fallback shouldn't be in iter() itself because falling back on the
sequence iterator is a bug when __getitem__ and __len__ are used to implement
a mapping.
Alternatively, if a mechanism is introduced to allow a class to explicitly
flag itself as "I'm a sequence", then iter() could be changed to only use the
sequence iterator if that marker was set.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-3000
mailing list