Update the Dictionary.get regarding the default argument & it's side effects

Co-authored-by: Danil Alexeev <dalexeev12@yandex.ru>
This commit is contained in:
AR 2026-02-10 17:38:20 +05:00
parent 833889aec0
commit 0ced9ff855

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">