[Python-ideas] Putting `blist` into collections module
Guido van Rossum
guido at python.org
Mon Sep 22 20:54:03 CEST 2014
On Mon, Sep 22, 2014 at 11:48 AM, <random832 at fastmail.us> wrote:
> On Sun, Sep 21, 2014, at 01:18, David Wilson wrote:
> > Coming from this perspective, I'd prefer that further additions were
> > limited to clean and far better understood structures. In this light,
> > could we perhaps instead discuss the merits of a collections.Tree,
> > collections.SortedDict or similar?
>
> As I understand it, the problem with a tree, SortedDict/SortedSet, or in
> general any collection that relies on comparison relationships (heap,
> etc), is: unlike hashing (where Hashable implies an immutable hash
> relationship), there is no way to detect whether an object implements an
> immutable well-defined ordering. And that, unlike a mutable hashed
> object (which can AIUI only lose itself), a mutable sorted object (or a
> badly-behaved one like NaN) can cause other objects in the set to be
> inserted in the wrong place or not found.
>
A good point, too often overlooked.
We could introduce a convention requiring __hash__() even though it is not
used by the implementation. After all, if the object is immutable when it
comes to a well-defined ordering, it is immutable when it comes to
equality. I don't really want to think about classes that are immutable
when it comes to == but not when it comes to <; that seems terrible.
--
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140922/25952ee6/attachment.html>
More information about the Python-ideas
mailing list