godot-docs icon indicating copy to clipboard operation
godot-docs copied to clipboard

Dictionary classref doesn't mention `StringName` -> `String` conversion

Open 5gTestSubject opened this issue 1 year ago • 2 comments

Your Godot version: 4.3

Issue description: Dictionary documentation does not mention that when working with keys, all StringNames are cast to Strings. Only reference to this i've found is one github comment from a maintainer.

This conversion included when iterating over keys in the dictionary! If a value is set in a dictionary with a StringName key, that StringName will not be present in the key collection; the stringified version of it will be given. (honestly this feels like a language/engine bug to me)

This causes difficult to diagnose behavior when working with key sets. Often someone will want to check the type of a variant to know how to interact with it (or surface errors). If they check for StringName, they will never find it, even though they can guarantee they used one as a key.

Since this is an exception to how every other type interacts with dictionaries, it should be called out in the docs. Ideally there should be a note about it in the opening class description, as well as the docs on get(), set(), and operator [].

URL to the documentation page (if already existing): https://docs.godotengine.org/en/stable/classes/class_dictionary.html#operators

5gTestSubject avatar Mar 18 '25 14:03 5gTestSubject

That's because it isn't done any more since 4.4:

  • https://github.com/godotengine/godot/pull/70096

We could document this specifically for 4.3 but on the stable documentation it shouldn't say this as it is not true

AThousandShips avatar Mar 18 '25 15:03 AThousandShips

@AThousandShips Oh wow! I'll see how possible it is for me to upgrade to 4.4. Typed dictionaries too! Those are long-wanted for me.

I checked the 4.4 release announcement page to see if I should have caught this anywhere. I notice that the linked migration guide doesn't mention this in breaking or behavioral changes (a search for "stringname" comes up blank). Considering there was a change to how dictionaries alter the data you give them, this seems like it would be worth mentioning in that migration guide.

5gTestSubject avatar Mar 18 '25 16:03 5gTestSubject