On Tue, Mar 7, 2017 at 1:47 PM Erik <pyt...@lucidity.plus.com> wrote:
> > I'd prefer the sort optimization to be based on what my list contains > NOW, not on what it may have contained some time in the past, so I'm not > a fan of the "once heterogeneous, always considered heterogeneous" > behaviour if it's cheap enough to avoid it. > Sure. Dictionaries actually don't implement this, though: as soon as they see a non-string key, they permanently switch to a heterogeneous state (IIRC). I think the bigger problem, though, is that most list use does *not* involve sorting, so it would be a shame to impose the non-trivial overhead of type-checking on *all* list use. With dictionaries, you have to type-check inserts anyway (for equality testing), so it's less of a problem. But the fundamental list operations *don't* require type-checking currently, so why add it in? In practice, the pre-sort check is *very* cheap, and its cost is only imposed on sort usage. Anyway, my patch could always be a precursor to a more general optimization along these lines. I'm almost finished fixing the problem Tim identified earlier in this thread; after that, it'll be ready for review!
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/