godotengine / godotengine/godot-docs

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

Open
#10,778 2 comments 0 reactions 0 assignees View on GitHub
area:class reference discussion enhancement
Dominant language
reStructuredText
Stars
5.7k
Forks
3.8k
Avg merge
1d 20h
Merged PRs (30d)
25

Description

**Your Godot version:** 4.3

**Issue description:**
Dictionary documentation does not mention that when working with keys, all `StringName`s are cast to `String`s. Only reference to this i've found is [one github comment](https://github.com/godotengine/godot/issues/62957#issuecomment-1182102372) 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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.