On Thu, Apr 16, 2020 at 01:11:46PM -0300, Soni L. wrote:
we can't break setdefault (particularly for tuple keys), do you have a better idea?
I don't have to suggest a better idea, since its not me proposing a change. I don't think any change is needed. It is up to you to firstly justify that a change is needed, and only then justify a specific response to that need.
An anecdote... when I first discovered Python back in 1.5 days, and specifically the dict.update method, practically the first thing I did was wonder why update replaced existing keys. What if I wanted it to keep the existing key, or raise an exception? So I immediately wrote a pair of functions to do both those things.
It's been close to 20 years now and so long as I can remember, I have never, not once, used either of those variants I don't even know whether I even still have them (not that it would be hard to recreate them).
If you personally would use them, I'm happy for you. But unless there is likely to be either moderate or widespread use among the community, or at least some uses in the stdlib, those functions belong in your own personal toolbox, not the stdlib.