{"record":{"id":"83cbedcecbad4e40","repo":"slint-ui/slint","slug":"callback-name-cannot-be-used-with-a-callback-d-83cbed","errorCode":null,"errorMessage":"Callback '{name}' cannot be used with a callback decorator for an async function, as it doesn't return void","messagePattern":"Callback '(.+?)' 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":192,"sourceCode":"                        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)\n\n                    return invoke\n\n                if \"global_name\" in callback_info:\n                    self.__instance__.set_global_callback(\n                        callback_info[\"global_name\"], name, mk_callback(self, value)\n                    )\n                else:\n                    self.__instance__.set_callback(name, mk_callback(self, value))\n","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/slint-ui/slint/blob/a9ea814a5813e7460fa1a867924872095a4d678d/api/python/slint/slint/__init__.py#L174-L210","documentation":"Component-level async callbacks must be declared void for the same reason as the global case: the coroutine return value cannot be handed back to Slint's synchronous callback invocation. If compdef.callback_returns_void(name) returns False (callback declared with a return type), constructing the subclass raises this RuntimeError.","triggerScenarios":"`callback lookup(key: string) -> string;` on the component plus `@slint.callback` + `async def lookup(self, key)` in Python; raised when the subclass instance is created, before the callback is ever invoked.","commonSituations":"Making an existing returning callback async without changing its declaration; mixing awaitable I/O with synchronous data binding; code migrated from sync handlers that kept `-> T`.","solutions":["Declare the callback without a return type: `callback lookup(key: string);` and reload the file.","Return data through a property or by invoking a Slint function from the coroutine when the result is ready.","Keep the handler synchronous if the callback genuinely must return a value to Slint expressions."],"exampleFix":"// before\nexport component App {\n    callback load(int) -> [string] ;\n}\n\n@slint.callback\nasync def load(self, id): ...  # RuntimeError at instantiation\n\n// after\nexport component App {\n    callback load(int);                 // async = fire-and-forget\n    out property <[string]> items;\n}\n\n@slint.callback\nasync def load(self, id):\n    self.items = await fetch_items(id)","handlingStrategy":"validation","validationCode":"# Lint: component-level async callbacks must be declared without `->`\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 my_async_callback_names:\n        raise SystemExit(f\"callback '{m.group(1)}' must be void (no '->') to use 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(\"Async callbacks must be declared void; deliver results via properties instead\") from e\n    raise","preventionTips":["When converting a handler to async, also drop the return type from the callback declaration.","Push results into out properties from inside the coroutine.","Add a startup smoke test that instantiates the subclass to surface signature mismatches early."],"tags":["python","slint","callbacks","async","return-type"],"backgroundTag":"callback-return-type-mismatch","analyzedSha":"a9ea814a5813e7460fa1a867924872095a4d678d","analyzedAt":"2026-08-16T22:39:12.830Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}