> I see this asymmetry between the | and |= mentioned a few times in the PEP, 
> but I don't see any rationale other than "the authors have decided".

I agree that this probably deserves to be addressed. I can't speak for Steven, 
but I know that my motivation here is to restrict `|` in order to avoid 
confusing casting. It suddenly becomes a very complicated problem with strange 
edge-cases as soon as reflected operations get involved. In contrast, `|=` 
appears in dramatically simpler contexts, so we don't need to worry about 
resolving all of the combinations of possible LHS and RHS types (or whether the 
user can keep up with what we're doing under-the-hood).

I have no idea if this is what motivated the decision in `list`, but I think 
it's a good one.

> The specification mentions "Dict union will return a new dict containing the 
> left operand merged with the right operand, which must be a dict (or an 
> instance of a dict subclass)." Can you clarify if it is part of the spec that 
> it will always return a dict even if one or both of the operands is a dict 
> subclass?

See my recent post on this here. I believe that we should call an overridden 
`lhs.copy()`, but others disagreed during code review. For what it's worth, 
it's probably not good for us to use "dict" and "`dict`" (with 
monospace/backticks) to mean different things in the PEP... ;)

> Unless there is compelling reason to do otherwise, I am in favor of trying to 
> retain subclass identity after operation.

I'll count you as a vote for `new = lhs.copy(); dict.update(new, rhs)`, then. ;)
_______________________________________________
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/MRYKAFWIJFODH7PBVH5CKPWAS2M26VFO/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to