{"record":{"id":"d5587f746342e4cd","repo":"slint-ui/slint","slug":"callback-name-cannot-be-used-with-a-callback-decorator-for-d5587f","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/bb937076de3f7919766c1f25e2e969367cf77e9a/api/python/slint/slint/__init__.py#L174-L210","documentation":"Raised by the @slint.callback decorator when decorating an async function whose component callback exists but has a non-void return type. Async handlers cannot supply return values to Slint callbacks, so the decorator rejects the combination.","triggerScenarios":"Applying @slint.callback(\"name\") to an `async def` where the component declares `callback name(...) -> someType`.","commonSituations":"Adding async/await to an existing handler that used to return a value; declaring a callback with a return type in .slint for sync use and later making the Python side async.","solutions":["Remove the return type from the Slint callback declaration so it returns void.","Make the Python handler synchronous so it can return the value.","Keep the handler async and deliver the result through a two-way property or another callback."],"exampleFix":"# before (.slint)\ncallback validate() -> bool;\n# Python\n@slint.callback(\"validate\")\nasync def validate(): return True  # RuntimeError\n\n# after (.slint)\nproperty <bool> valid;\ncallback validate();  # async handler sets `valid` instead of returning","handlingStrategy":"validation","validationCode":"if asyncio.iscoroutinefunction(fn) and not comp.callback_returns_void(name):\n    raise TypeError(f\"async handler for '{name}' requires a void callback\")","typeGuard":"def is_async_handler(fn):\n    return asyncio.iscoroutinefunction(fn)","tryCatchPattern":"try:\n    component.validate = async_handler\nexcept RuntimeError as e:\n    logging.error(\"use a sync handler or a void callback: %s\", e)","preventionTips":["Declare callbacks used by async handlers as `callback name(args);` with no return type.","Standardize on sync handlers for value-returning callbacks."],"tags":["python","callback","async","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}