{"record":{"id":"b80ba0d921362455","repo":"slint-ui/slint","slug":"callback-name-in-global-global-name-cannot-be-used-with-a-b80ba0","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/bb937076de3f7919766c1f25e2e969367cf77e9a/api/python/slint/slint/__init__.py#L164-L200","documentation":"Raised by the @slint.callback decorator when decorating an async function that targets a global callback declared in the .slint file whose return type is not void. Async Python callbacks can only be wired to Slint callbacks that return nothing, because the runtime fires the callback without awaiting a result value to hand back to the Slint side.","triggerScenarios":"Applying slint.callback() to an `async def` handler whose `name` refers to a callback in a global (exported global component) that was declared with a non-void return type, e.g. `callback foo(int) -> string`.","commonSituations":"Declaring a global callback with a return type in .slint (for the sync variant) and later switching the Python handler to async without changing the declaration; mixing async/await refactors into existing global callback handlers.","solutions":["Change the Slint global callback declaration to return nothing: remove `-> type` from `callback name(...) -> type`.","Make the Python handler a regular (non-async) function and return the value synchronously if the Slint side needs a result.","Keep the handler async but communicate the result via a property or a separate void callback instead of the return value."],"exampleFix":"# before (.slint)\nexport global Logic { callback compute(int) -> int; }\n\n# Python (async) -> RuntimeError\n@slint.callback(\"compute\")\nasync def compute(x): return x * 2\n\n# after: either make it void in .slint, or use a sync handler\n@slint.callback(\"compute\")\ndef compute(x):\n    return x * 2","handlingStrategy":"validation","validationCode":"def check_void_callback(comp, name):\n    if comp.callback_returns_void(name) is False:\n        raise TypeError(f\"callback '{name}' returns a value; async handler not allowed\")","typeGuard":"def is_async_handler(fn):\n    return asyncio.iscoroutinefunction(fn)","tryCatchPattern":"try:\n    component.compute = handler\nexcept (RuntimeError, AttributeError) as e:\n    logging.error(\"callback binding failed: %s\", e)","preventionTips":["Keep async handlers only for callbacks declared without `-> type` in .slint.","Use the Slint LSP to confirm callback signatures when writing handlers."],"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"}