{"record":{"id":"2184201ee64edf09","repo":"slint-ui/slint","slug":"callback-name-in-global-global-name-cannot-be-used-with-a","errorCode":null,"errorMessage":"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","messagePattern":"Callback '(.+?)' in global '(.+?)' cannot be used with a callback decorator for an async function, as it is not declared in Slint component","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"api/python/slint/slint/__init__.py","lineNumber":178,"sourceCode":"def _build_class(\n    compdef: native.ComponentDefinition,\n) -> typing.Callable[..., Component]:\n    def cls_init(self: Component, **kwargs: Any) -> Any:\n        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(","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/api/python/slint/slint/__init__.py#L160-L196","documentation":"In the Python API, the async-callback decorator checks the declared global callback via compdef.global_callback_returns_void. When the lookup returns None the callback is not declared on the Slint global, so setting an async handler is impossible and an AttributeError is raised.","triggerScenarios":"Using @slint.callback (async variant) with a global name whose callback does not exist in the .slint component, typically due to a typo in name or global name.","commonSituations":"Renaming a callback in .slint without updating Python, wrong global alias, decorator applied before the component was compiled with that global.","solutions":["Declare the callback on the global in the .slint file (callback <name>(...) -> void).","Check the callback and global names for typos against the .slint markup.","Ensure the decorated function returns nothing (void); non-void callbacks use the non-async path.","Recompile/refresh the component instance before applying decorators."],"exampleFix":"// before (.slint global missing the callback)\n# Python: @slint.callback('my_global', 'do_thing')\n// after — add to .slint global:\nglobal MyGlobal { callback do-thing(); }","handlingStrategy":"validation","validationCode":"names = {c['name'] for c in compdef.properties}  # or inspect compiled callbacks\ncallbacks = {info['name'] for info in compdef.callback_infos('my_global')}\nassert 'do_thing' in callbacks, 'callback not declared in Slint component'","typeGuard":"def callback_declared(compdef, global_name: str, name: str) -> bool:\n    return compdef.global_callback_returns_void(global_name, name) is not None","tryCatchPattern":"try:\n    @slint.callback('my_global', 'do_thing')\n    async def handler(self, *args):\n        ...\nexcept AttributeError as e:\n    logging.error('callback not declared in .slint: %s', e)","preventionTips":["Keep callback names in .slint and Python decorators in sync; rename via search across both.","Verify the global name/alias matches the one exported by the component.","Ensure async-decorated callbacks are declared void in .slint."],"tags":["python","callback","slint","decorator"],"backgroundTag":"entity-not-found","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"}