Add a get_or_add method to Dictionary - #78095
Conversation
ajreckof
left a comment
There was a problem hiding this comment.
The implementation is quite simple and in line with other dictionary functions. I'm just not sure about the name but I can't find a better one and python setDefault is even worse so this might be the best name😓
|
My issue with |
|
I am good with either of the proposed names, none seems obviously better to me. Really, it's more like "(get) or ((set and get) default)". |
|
Don't you like |
|
I think |
|
At this point I don't think the full behavior of the method can be summarized enough without leaving some thought to the user. In the defense of |
|
What about |
|
How about |
I support that. Just let's be sure that |
|
Maybe "insert" is more used in Godot containers in general.
|
|
We should instead use what similar languages were offering, in this case https://docs.python.org/2/library/stdtypes.html If this PR gets merged successfully, I'll try to cherry pick this to 3.x |
|
I really don't like the Python set_default as it is really unclear on what it does |
32a5f39 to
f238cc2
Compare
f238cc2 to
ad22506
Compare
ad22506 to
537f5c1
Compare
|
I read |
|
@RandomShaper "Insert" is usually associated with some kind of order, like with Array.insert(), so I would prefer to not use that terminology here. This method does not affect the order, if anything is added then it always goes to the "end". |
|
Back to |
|
Sorry, I didn't see |
537f5c1 to
65e5156
Compare
|
I think there's a relatively good consensus for |
65e5156 to
8b7d99e
Compare
get_or_set_default method to Dictionaryget_or_add method to Dictionary
|
The commit message also needs to be amended. |
8b7d99e to
437586b
Compare
|
Thanks! |
…-default Add a `get_or_add` method to Dictionary
…-default Add a `get_or_add` method to Dictionary

Implements this proposal and closes godotengine/godot-proposals#7059