-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a get_or_add
method to Dictionary
#78095
Add a get_or_add
method to Dictionary
#78095
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! |
Implements this proposal and closes godotengine/godot-proposals#7059