{"action":"created","issue":{"url":"https://api.github.com/repos/godotengine/godot/issues/20318","repository_url":"https://api.github.com/repos/godotengine/godot","labels_url":"https://api.github.com/repos/godotengine/godot/issues/20318/labels{/name}","comments_url":"https://api.github.com/repos/godotengine/godot/issues/20318/comments","events_url":"https://api.github.com/repos/godotengine/godot/issues/20318/events","html_url":"https://github.com/godotengine/godot/issues/20318","id":343287550,"node_id":"MDU6SXNzdWUzNDMyODc1NTA=","number":20318,"title":"Annotations in GDScript","user":{"login":"vnen","id":5599796,"node_id":"MDQ6VXNlcjU1OTk3OTY=","avatar_url":"https://avatars3.githubusercontent.com/u/5599796?v=4","gravatar_id":"","url":"https://api.github.com/users/vnen","html_url":"https://github.com/vnen","followers_url":"https://api.github.com/users/vnen/followers","following_url":"https://api.github.com/users/vnen/following{/other_user}","gists_url":"https://api.github.com/users/vnen/gists{/gist_id}","starred_url":"https://api.github.com/users/vnen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vnen/subscriptions","organizations_url":"https://api.github.com/users/vnen/orgs","repos_url":"https://api.github.com/users/vnen/repos","events_url":"https://api.github.com/users/vnen/events{/privacy}","received_events_url":"https://api.github.com/users/vnen/received_events","type":"User","site_admin":false},"labels":[{"id":279097162,"node_id":"MDU6TGFiZWwyNzkwOTcxNjI=","url":"https://api.github.com/repos/godotengine/godot/labels/discussion","name":"discussion","color":"ee77ee","default":false},{"id":73330068,"node_id":"MDU6TGFiZWw3MzMzMDA2OA==","url":"https://api.github.com/repos/godotengine/godot/labels/feature%20proposal","name":"feature proposal","color":"1144ff","default":false},{"id":279098082,"node_id":"MDU6TGFiZWwyNzkwOTgwODI=","url":"https://api.github.com/repos/godotengine/godot/labels/topic:gdscript","name":"topic:gdscript","color":"ffdd44","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-07-21T01:55:09Z","updated_at":"2018-07-21T02:59:12Z","closed_at":null,"author_association":"MEMBER","body":"Around a year ago there was a PR adding annotations for GDScript (#9469). It was rejected mainly because there was no direct use for it (no data in the parse tree, only third-party tools would made use of it).\r\n\r\nThis proposal is to add some use for annotations in a way that make GDScript more extensible without hacking more keywords into it.\r\n\r\n**What annotations could be used for?**\r\n- `export` hints. Right now it uses a custom syntax for each type. With annotations it could set directly the usage and hint for the PropertyInfo, making better use of new additions to the Inspector without having to hack a new syntax in the GDScript parser.\r\nTo be clear, I would leave the `export` keyword, just the hints would move to annotations. Type can be defined with type hints.\r\n- This includes categories for `export` too (#4378, #10303).\r\n- Replace `onready` keyword with an annotation.\r\n- Disabling certain warnings. #19993 add warnings with an ad-hoc syntax for disabling them, but it could use annotations instead.\r\n- `setget` (it is kind of a weird syntax when you want only the getter).\r\n- RPC keywords (`master`, `slave`, `sync`, `remote`).\r\n- New pre-processor instructions, like making a function compile only in editor (with `tool`) or only in debug mode (related to #12837).\r\n- Eventual discussion of new syntax (like signal to emit when variable change: #6491).\r\n- Maybe the possibility of adding custom \"decorators\".\r\n\r\n**Advantages**\r\nEvery time a new keyword is added, it requires changes to the GDScript tokenizer and parser to handle it. In particular the `export` parsing is quite convoluted and it's mixed with other class-related parsing.\r\n\r\nWith annotations, less work would be done to add a particular attribute (like export, setget, onready), instead it would only need to check which annotations are present.\r\n\r\n**DIsadvantages**\r\nAdding annotation support would require more changes to the parser than any keyword alone. It may also influence people to suggest new features as \"just an annotation\".\r\n\r\n**Syntax**\r\nI don't have any particular preference for syntax, but I imagine something like Python decorators. It might be confusing for Python users though, since annotations are not the same as decorators.\r\n\r\n```gdscript\r\n@onready\r\nvar my_sprite = $Sprite\r\n```\r\n\r\nFor passing arguments, it could work like functions:\r\n\r\n```gdscript\r\n@export_hint(ENUM)\r\n@export_hint_string(\"Attack,Defense\")\r\nexport var my_enum : int = 0\r\n```\r\n\r\nMaybe without parentheses:\r\n\r\n```gdscript\r\n@export_hint ENUM\r\n@export_hint_string \"Attack,Defense\"\r\nexport var my_enum : int = 0\r\n```\r\n\r\nOr maybe use named parameters (and avoid the keyword):\r\n\r\n```gdscript\r\n@export type=String hint=MULTILINE\r\nvar my_text = \"\"\r\n```\r\nOr something else.\r\n\r\n**Custom annotations**\r\nUnknown annotations will simply be ignored (maybe with a warning). So third-party tools can parse the annotations to offer other capabilities, like documentation generation.\r\n\r\nIt's also possible to add an introspection API: `get_method_annotations()`, `get_property_annotations()` or something like that. This way plugins that, say, expect scripts can use annotations to decide which method to call instead of using a hard-coded name.\r\n"},"comment":{"url":"https://api.github.com/repos/godotengine/godot/issues/comments/406766006","html_url":"https://github.com/godotengine/godot/issues/20318#issuecomment-406766006","issue_url":"https://api.github.com/repos/godotengine/godot/issues/20318","id":406766006,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNjc2NjAwNg==","user":{"login":"vnen","id":5599796,"node_id":"MDQ6VXNlcjU1OTk3OTY=","avatar_url":"https://avatars3.githubusercontent.com/u/5599796?v=4","gravatar_id":"","url":"https://api.github.com/users/vnen","html_url":"https://github.com/vnen","followers_url":"https://api.github.com/users/vnen/followers","following_url":"https://api.github.com/users/vnen/following{/other_user}","gists_url":"https://api.github.com/users/vnen/gists{/gist_id}","starred_url":"https://api.github.com/users/vnen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vnen/subscriptions","organizations_url":"https://api.github.com/users/vnen/orgs","repos_url":"https://api.github.com/users/vnen/repos","events_url":"https://api.github.com/users/vnen/events{/privacy}","received_events_url":"https://api.github.com/users/vnen/received_events","type":"User","site_admin":false},"created_at":"2018-07-21T02:59:12Z","updated_at":"2018-07-21T02:59:12Z","author_association":"MEMBER","body":"@LikeLakers2 yes, that is the gist of it."}}
{"actor":{"display_login":"vnen"}}