Jan Greis wrote:
> On 22/10/2019 06:43, Richard Musil wrote:
> > It is not a "concatenation" though, because you lost
> > {"key1": "val1"} 
> > in the process. The concatenation is not _just_ "writing something 
> > after something", you can do it with anything, but the actual 
> > operation, producing the result.
> > My point is that if I saw {"key1": "val1", "key2": "val2"} + {"key1": 
> "val3"}, I would expect that it would be equivalent to {"key1": "val1", 
> "key2": "val2", "key1": "val3"}.

But that reasoning only works with literals. And chances are that you're not 
going to see something like this in real code. Because why would you add two 
dict literals?

Instead you're going to see something like this: `d1 + d2`. And if one has to 
infer the details of that operation by coming up with some hypothetical example 
involving literals, that doesn't speak in favor of the syntax.

As mentioned, here it is up to the variable names to be clear about what 
happens. E.g.

    default_preferences + user_preferences

For that example it's pretty clear that `user_preferences` is meant to 
supersede `default_preferences`. But variable names might not always be 
completely clear or even if they are, they might not allow the reader to infer 
any precedence. And then, "in the face of [that] ambiguity", one has to "refuse 
the temptation to guess". Maybe it's better not to introduce that ambiguity in 
the first place.

> Similarly, I would expect that
> deque([1, 2, 3], maxlen=4) + deque([4, 5]) == deque([1, 2, 3, 4, 5], 
> maxlen=4) == deque([2, 3, 4, 5], maxlen=4)
> which indeed is true.
_______________________________________________
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/RDBCJGWMK45RY676YEXQATIPHWMLVQ3Z/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to