[Python-3000] Iterators for dict keys, values, and items == annoying :)
Brett Cannon
brett at python.org
Wed Mar 29 09:11:50 CEST 2006
On 3/28/06, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Adam DePrince wrote:
>
> > The following interface names are abbreviations for the following
> > permutations of the above.
> >
> > * Collection View( SetView + Multiview )
> > * ListView: (SetView + MultiView + OrderedView)
> > * OrderedSetView (SetView + OrderedView )
> > * MapView( SetView + MappingView )
> > * OrderedMapView( SetView + MappingView + OrderedView )
> > * MultiMapView( SetView + MultiView + MappingView )
> > * OrderedMultiMapView( SetView + CollectionView + MappingView + OrderedView )
>
> Nooooo....
>
> This is massive over-design.
>
> Python is NOT Java!
>
What I was taking away from this whole view discussion was basically
just coming up with a simple, minimal, set/container interface that
allows one to know about what a data structure contains. So I
basically expected that it would implement __contains__, __len__, and
if people wanted delete(obj) (optional or not). Basically a simple
set interface where we could have a __container__/__view__/__set__
whatever method to call to get a view of the data structure.
Basically a read-only (with a possible delete possibility) mapping
interface.
I am with Greg with wanting to minimize any official protocols we
have. Iterators were desirable because they formalized how 'for'
loops worked. The reason the view topic came up was people wanted to
be able to know if an iterator had any value to return without having
to call next(). So the proposed interface has a use, it doesn't
directly tie into why we added iterators as much. Perhaps if people
need to know if a specific iterator has a certain amount their
iterator can also implement __len__, but it obviously would not be
part of the iterator interface.
Without a direct reason in terms of the language needing a
standardization of an interface, perhaps we just don't need views. If
people want their iterator to have a __len__ method, then fine, they
can add it without breaking anything, just realize it isn't part of
the iterator protocol and thus may limit what objects a function can
accept, but that is there choice.
-Brett
More information about the Python-3000
mailing list