> 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.

> This would make it very elegant to 'normalize' dicts by pruning (dict & set) 
> or padding (set | dict) dictionaries.

Well, if the PEP lands, the padding part is easy:

padded = dict.fromkeys(expected) | given

Or even better, just do the dict.fromkeys construction at module level once, 
and do:

padded = EXPECTED | given

Or, implement the behavior in a subclass if you truly need it to be a set! 
We're intentionally very subclass-friendly (unlike list, for example).
_______________________________________________
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/G3NWWUFR3SJECCXIAUGHNEJLSCBQBEVG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to