[Python-3000] Iterators for dict keys, values, and items == annoying :)

Guido van Rossum guido at python.org
Fri Mar 31 01:47:49 CEST 2006


On 3/30/06, Ian Bicking <ianb at colorstudy.com> wrote:
> Set-like is anything that subclasses baseset?

No, it should to support duck typing.

> But maybe there's a
> deeper answer somewhere, as base* types seem a bit kludgy.

Not just kludgy, but unpythonic.

> A collection-specific protocol for testing equality would be reasonable.

I'm not sure what you mean here. Are you proposing using a different
method than __eq__()?

> It doesn't break duck typing, just adds a bit more to the interfaces of
> collections than purely a bunch of disparate methods.
>
> A generic view protocol could maybe handle it too, so you'd ask an
> object to give a set-like view of itself when comparing that object to a
> set, and then test that.  And the object could return itself, if it
> already implemented a set-like view.  Or return None, meaning no such
> view was possible.  At which point it sounds just like adaptation.

That's definitely an interesting thought, but I'm not sure if it'll go
anywhere. I wouldn't want this to turn into the creation of a new set
object (a copy); if it can't be a view, it should be refused. That's
different from adaptation. I don't want copies to be created because
views ought to be lightweight; that's part of the contract for views.
If the caller doesn't mind a copy to be taken, they should just use
set(x) directly.

FWIW, if anyone is reading the Java collections framework docs, their
"abstract" classes are really implementation helpers along the lines
of Python's DictMixin. (In Java they can't be mixins because of the
constraint to single inheritance.)

--
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list