On Mon, Mar 16, 2020 at 2:22 PM Andrew Barnert <abarn...@yahoo.com> wrote:
> > Yes, everyone who designs a sorted container library runs into the fact > that a SortedList is a Sequence, and mutable, but not even close to a > MutableSequence—it’s not just append and extend; you can’t even do > __setitem__. In fact, it’s a lot closer to a MutableSet (assuming you use > the obvious names add and update), but it’s not that either, because it’s a > multiset rather than a set. > > I believe SortedContainers 2.x’s SortedList inherits MutableSequence > anyway, and raises NotImplementedError on __setitem__, append, etc. Which > is a weird compromise, sometimes confusing but sometimes handy. > There's a gitHUb issue about that -- not sure how it will be resolved. Personally a bigger fan of EAFTP Duck Typing than ABCs and isinstance(), but if you are going to inherit form an ABC, it should be correct :-) Otherwise it really kinda kills the point of any kind of type checking (dynamic or static), no? > > I think the best solution is to just not have a SortedList. > Interesting -- I wonder if the SortedContainers folks have any idea how often it's used. 90% of the use cases for SortedContainers and its competitors are dicts. > No idea how to know for sure, but it's a lot easier ta add one, and wait to see if anyone clammers for more, than to add a bunch that are rarely used., and have to maintain or deprecate them. So it seems we have a pretty simple proposal here: Add SortedDict, much like implemented in the SortedContainers package, to the standard library's collections module. Now we just need someone to champion it. Oddly, I don't think the OP has responded at all to this thread :-) -CHB -- Christopher Barker, PhD Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/ON5CVFXLCIHBQ4QIRWO2Q5ACQ7WAIKJG/ Code of Conduct: http://python.org/psf/codeofconduct/