Merge pull request #116129 from AR-DEV-1/116086

Update the `Dictionary.get` documentation regarding the `default` argument & its side effects
This commit is contained in:
Thaddeus Crews 2026-02-16 15:02:30 -06:00
commit 003cc3d84b
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC

View file

@ -256,6 +256,13 @@
<param index="1" name="default" type="Variant" default="null" />
<description>
Returns the corresponding value for the given [param key] in the dictionary. If the [param key] does not exist, returns [param default], or [code]null[/code] if the parameter is omitted.
[b]Note:[/b] If the [param default] argument is computationally expensive or has unwanted side effects, consider using the [method has] method instead:
[codeblock]
# Always calls `expensive_function()`.
dict.get("key", expensive_function())
# Calls `expensive_function()` only if the key does not exist.
dict.get("key") if dict.has("key") else expensive_function()
[/codeblock]
</description>
</method>
<method name="get_or_add">