On Wed, Jul 1, 2020 at 8:37 AM Stestagg <stest...@gmail.com> wrote:

>  1. ordered collections that have some set-like operators added for
> convenience, (conceptually, if not exactly, class ...(Set, Sequence):)  but
> are missing a single method full Sequence interface (__getitem__)
> or
>  2. Sets that happen to have a stable/deterministic element order
>
> My opinion is that, as of Python 3.7, they are effectively 1, even if the
> isinstance hooks haven't been updated.  I can see why people may think of
> them as 2. I don't have any desire to change minds on this :)
>
> Semantic quibbling aside, My opinions/reasoning on the different options
> are the following:
>

as long as we are semantic quibbling (1) is not quite right -- they don't
"have some set-like operators, they have the full set of them, and they
they ARE Sets:

In [44]: d = {"this": 4, "that": 23}


In [45]: isinstance(d.keys(), Set)

Out[45]: True

But see another recent thread on this list - they don't have all the same
methods as the builtin set() type. But the ABC doesn't specify those, so
they don't need to.

However, that doesn't mean that it's somehow critical for them not to grow
some extra functionality -- they would still be Sets.

* Add numeric `__getitem__` to `dict_*` view classes:

> +1  - This restores code that used to work in python 2, and makese some
> things a bit easier.  The O(n) behaviour is not ideal, but in my opinion is
> an acceptable compromise
>

well, not really -- it only lets some things work like they did in Py2:
most code I've ported from py2 to py3 that I needed to wrap list() around
the views needed more than indexing -- I usually needed the list itself to
be a persistent, mutable Sequence, not a view.

I'm +1 on on this, ;cause why not? but honestly , the only good use case
I've seen is random.choice() -- and while I've needed that, I can't say
I've needed it often.


> * Add new method to dict class:
> -1 This doesn't feel like a good solution to me.  Rather than continue to
> argue about the justification for why, let's just say its a personal
> judgement
>

wqe neither, gut it's not just a personal taste -- a getter wouldn't work
with random.choice, the only known use case :-)  -- unless the new method
returned a Sequence-like view that could be indexed.

Granted, it would allow an easier way to get a random item, but not as
slick as:

random.choice(a_dict.items())

I think it was Oscar that pointed out that repeated indexing of a view
would be worse performance wise than making a proper list -- so that
*might* be considered an attractive nuisance.

-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/RMFV2PJBFXI5QFT3L3K6G45VG4QGZVIY/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to