Skip to content

GDScript: Update annotation description and development guidelines #11070

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 48 additions & 21 deletions contributing/development/core_and_modules/scripting_development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,57 @@ GDScript
Annotation guidelines
~~~~~~~~~~~~~~~~~~~~~

..
This description intentionally avoids mention of implementation and
compilation details because these are often inconsistent between annotations
In Godot 3 we had a lot of keywords (including ``tool``, ``export``, ``onready``).
This had the following disadvantages:

Create annotations for modifiers that act on the script or its code.
Additionally, create annotations for behavior that is specific to the Godot
engine and editor; if the primary purpose is to affect the way that the engine
or editor treats or interacts with the script, implement the token as an
annotation.
- Overcomplication of the language grammar.
- Possible conflicts with user identifiers.
- Need to touch the parser in a major way to add a new keyword.

Do not create annotations for general programming language features.
So in Godot 4 we introduced the concept of annotations. An annotation is a modifier
(an attribute, a marker) that can be applied to an entire script, a declaration,
a statement, or a location in the source code. Annotations can optionally take
additional arguments, listed in parentheses. Annotation arguments must be constant
expressions or string literals (in a few special cases where the argument value
must be resolved in the parser rather than in the analyzer).

::
Currently, an annotation target can be a combination of the following
``GDScriptParser::AnnotationInfo::TargetKind`` flags:

# Affects how the editor treats this script.
@icon("res://path/to/class/icon.svg")

# Affects how the engine interacts with this script.
@onready var character_name = $Label
+-----------------+----------------------------------------------+-----------------------------+
| **Target Kind** | **Description** | **Example** |
+=================+==============================================+=============================+
| ``SCRIPT`` | The entire script. | ``@tool`` |
+-----------------+----------------------------------------------+-----------------------------+
| ``CLASS`` | A class (both the outermost and inner ones). | ``@abstract`` |
+-----------------+----------------------------------------------+-----------------------------+
| | ``VARIABLE`` | Other types of class members. | ``@export`` |
| | ``CONSTANT`` | | |
| | ``SIGNAL`` | | |
| | ``FUNCTION`` | | |
+-----------------+----------------------------------------------+-----------------------------+
| ``STATEMENT`` | Statements inside a function. | ``@warning_ignore`` |
+-----------------+----------------------------------------------+-----------------------------+
| ``STANDALONE`` | Some place inside a class or a line | | ``@export_category`` |
| | in the source code. | | ``@warning_ignore_start`` |
| | | |
| | 1. Class pseudo-members. | |
| | 2. Markers for the start and end | |
| | of a warning-ignoring region. | |
+-----------------+----------------------------------------------+-----------------------------+

# static is a general programming language feature.
static var num_players = 2
**When to use a keyword and when an annotation to implement a new feature?**

For historical reasons, some existing annotations and keywords do not strictly
follow these guidelines. Choosing between implementing a feature as an
annotation or as a language keyword is a nuanced decision that should be made
through discussion with other GDScript developers.
- **General rule:** Do not use keywords unless they are required by the language grammar
and the parser. Do not use annotations for independent syntactic units.
- Use keywords for class member declarators (``var``, ``const``, ``func``).
- Use annotations for class member modifiers (``@export``, ``@onready``, ``@abstract``).
- Use keywords for operators within expressions (``and``), for delimiters in statements
(``in``, ``when``) and declarations (``extends``).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(``in``, ``when``) and declarations (``extends``).
(``in``, ``when``), and declarations (``extends``).


.. note::

For historical reasons, some existing annotations and keywords do not strictly
follow these guidelines. Choosing between implementing a feature as an annotation
or as a language keyword is a nuanced decision that should be made through discussion
with other GDScript developers.
6 changes: 3 additions & 3 deletions tutorials/scripting/gdscript/gdscript_basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,9 @@ GDScript also supports :ref:`format strings <doc_gdscript_printf>`.
Annotations
-----------

Annotations are special tokens in GDScript that act as modifiers to a script or
its code and may affect how the script is treated by the Godot engine or
editor.
Annotations are special tokens in GDScript that act as modifiers to an entire script,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recognize it's rather nitpicky, but I feel like it might be better to move "an entire script" to the last item in this list, since it encompasses the most. I can't think of a formal rule in English that specifies this, but my intuition just says that including the largest option first causes the later ones to be a bit more confusing.

Copy link
Member Author

@dalexeev dalexeev Jun 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand what you meant, but I went from up to down. If we invert the direction, a location in the source code will appear first, which is also not good in my opinion, since it is a more specific case.

a declaration, a statement, or a location in the source code. Annotations may affect
how the script is treated by the Godot editor and the GDScript compiler.

Every annotation starts with the ``@`` character and is specified by a name. A
detailed description and example for each annotation can be found inside the
Expand Down