{"record":{"id":"309837bf4ab06779","repo":"slint-ui/slint","slug":"callback-name-in-global-global-name-cannot-309837","errorCode":null,"errorMessage":"Callback '{name}' in global '{global_name}' cannot be used with a callback decorator for an async function, as it doesn't return void","messagePattern":"Callback '(.+?)' in global '(.+?)' cannot be used with a callback decorator for an async function, as it doesn't return void","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"api/python/slint/slint/__init__.py","lineNumber":182,"sourceCode":"        self.__instance__ = compdef.create()\n        for name, value in self.__class__.__dict__.items():\n            if hasattr(value, \"slint.callback\"):\n                callback_info = getattr(value, \"slint.callback\")\n                name = callback_info[\"name\"]\n\n                is_async = getattr(value, \"slint.async\", False)\n                if is_async:\n                    if \"global_name\" in callback_info:\n                        global_name = callback_info[\"global_name\"]\n                        is_void = compdef.global_callback_returns_void(\n                            global_name, name\n                        )\n                        if is_void is None:\n                            raise AttributeError(\n                                f\"Callback '{name}' in global '{global_name}' cannot be used with a callback decorator for an async function, as it is not declared in Slint component\"\n                            )\n                        if not is_void:\n                            raise RuntimeError(\n                                f\"Callback '{name}' in global '{global_name}' cannot be used with a callback decorator for an async function, as it doesn't return void\"\n                            )\n                    else:\n                        is_void = compdef.callback_returns_void(name)\n                        if is_void is None:\n                            raise AttributeError(\n                                f\"Callback '{name}' cannot be used with a callback decorator for an async function, as it is not declared in Slint component\"\n                            )\n                        if not is_void:\n                            raise RuntimeError(\n                                f\"Callback '{name}' cannot be used with a callback decorator for an async function, as it doesn't return void\"\n                            )\n\n                def mk_callback(\n                    self: Any, callback: typing.Callable[..., Any]\n                ) -> typing.Callable[..., Any]:\n                    def invoke(*args: Any, **kwargs: Any) -> Any:\n                        return callback(self, *args, **kwargs)","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/slint-ui/slint/blob/a9ea814a5813e7460fa1a867924872095a4d678d/api/python/slint/slint/__init__.py#L164-L200","documentation":"For @slint.callback-decorated async functions bound to a global, Slint requires the callback to be declared with no return type (void). Async handlers return a coroutine to Slint's synchronous callback invocation, so a return value cannot be delivered; if global_callback_returns_void() returns False (callback exists but is declared `-> something`), instantiation raises this RuntimeError.","triggerScenarios":"`callback fetch(name: string) -> string;` declared inside a global in .slint, combined with `@slint.callback` + `async def fetch(self, name)` in the Python subclass of the component. The error is raised when the component instance is constructed.","commonSituations":"Porting a synchronous callback (that returns a value) to async by just adding `async`; wanting to await I/O inside the handler while keeping the old `-> T` declaration; forgetting that async callbacks in Slint are fire-and-forget.","solutions":["Declare the callback without a return type in the global: `callback fetch(name: string);` and reload the .slint.","Deliver results asynchronously by setting a property (or calling a Slint function) from the coroutine after the await completes.","If Slint must consume a return value synchronously, keep the callback sync (no `async def`)."],"exampleFix":"// before (main.slint)\nexport global Net { callback query(string) -> string; }\n\n@slint.callback\nasync def query(self, q): ...  # RuntimeError at instantiation\n\n// after\nexport global Net {\n    callback query(string);          // fire-and-forget\n    out property <string> result;\n}\n\n@slint.callback\nasync def query(self, q):\n    self.Net.result = await do_query(q)  # push result via property","handlingStrategy":"validation","validationCode":"# Lint: async @slint.callback handlers on globals must map to `callback name(...);` with no `->`\nimport re\nsrc = open(\"app.slint\").read()\nfor m in re.finditer(r\"callback\\s+(\\w+)\\s*\\([^)]*\\)\\s*->\", src):\n    if m.group(1) in async_global_callbacks:\n        raise SystemExit(f\"global callback '{m.group(1)}' must be void for an async handler\")","typeGuard":null,"tryCatchPattern":"try:\n    app = App()\nexcept RuntimeError as e:\n    if \"doesn't return void\" in str(e):\n        raise SystemExit(\"Declare the async callback without a return type and push results via properties\") from e\n    raise","preventionTips":["Treat async callbacks as fire-and-forget: declare them without a return type from the start.","Return data via out properties or function calls from the coroutine.","Keep synchronous handlers for callbacks Slint expressions consume values from."],"tags":["python","slint","callbacks","async","return-type","globals"],"backgroundTag":"callback-return-type-mismatch","analyzedSha":"a9ea814a5813e7460fa1a867924872095a4d678d","analyzedAt":"2026-08-16T22:39:12.830Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}