On Thu, Feb 6, 2020 at 3:47 AM Brandt Bucher <brandtbuc...@gmail.com> wrote:
>
> > I have one suggestion: Wouldn't it be useful for these operators to also 
> > accept sets (functionally acting like a dict with None for all values)?
>
> > Why None?  Why not 0, or False, or 42?  This sort of thing belongs more  in 
> > a function or method, IMHO.
>
> Well, in their defense, None is the null object in Python, so it would be a 
> natural choice. With that said, I am strongly against this for several 
> reasons:
>
> - The proposal in its current form is very easy to wrap your head around: "|" 
> takes dicts, "|=" takes anything dict.update does.
> - Python doesn't allow sets to be dictionaries anywhere else. It's much more 
> natural to use a dict like a set than to use a set like a dict. Hence, this 
> PEP!
> - A consistent argument that we've gotten since the very beginning is 
> something to the effect of "I don't know what types are being used in the 
> expression 'a | b'." While we argue that this isn't the issue in practice 
> that people make it out to be, accepting sets here would definitely muddy the 
> waters.
>

- and you can use dict.fromkeys to "upgrade" a set to a dict anyway.

If this goes through as is, and then in a few years' time we start
seeing lots of people begging to be able to skip the explicit fromkeys
and accept sets directly, it can be addressed then. Personally, I
think sets make good sense on the right hand side of an intersection
(as a means of saying "whitelist the keys to this set"; values would
be irrelevant there anyway), but not with union/update.

ChrisA
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/NZWJDWAHGJSOMI23ZAU5CDEC4BHJMFRT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to