{"record":{"id":"a45df397836f9020","repo":"slint-ui/slint","slug":"callback-name-in-global-global-name-cannot","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/a9ea814a5813e7460fa1a867924872095a4d678d/api/python/slint/slint/__init__.py#L160-L196","documentation":"When a Python class subclasses a generated Slint component and decorates an `async def` method with @slint.callback (with a global_name in the callback info), Slint validates at instantiation time that the global actually declares that callback: compdef.global_callback_returns_void(global_name, name) returns None when the callback does not exist in the Slint global, which raises this AttributeError. It fires from cls_init, i.e. the moment you construct the subclass.","triggerScenarios":"`@slint.callback` on an `async def` method of a global shim class where the method name does not match any `callback` declared inside the corresponding `export global { ... }` in the .slint file (typos, renamed callback, dashes vs underscores mismatch, or a helper method decorated by mistake).","commonSituations":"The callback was renamed in .slint but not in Python (or vice versa); the .slint file was edited but slint.load_file was not re-run; the developer decorated a plain helper method with @slint.callback; forgetting that Slint names with dashes map to Python underscores.","solutions":["Declare the callback inside the global in the .slint file: `export global Foo { callback clicked(); }`.","Make the Python method name match the Slint callback name exactly (use underscores where .slint uses dashes).","Re-run slint.load_file()/load_str() with the updated .slint before instantiating the subclass.","If the method is not meant to be invoked from Slint, remove the @slint.callback decorator from it."],"exampleFix":"# before (main.slint)\nexport global Actions { callback submit(string); }\n\n# app.py — no `quit` callback exists in the global\n@slint.callback\nasync def quit(self): ...\n\n# after — declare it first\nexport global Actions {\n    callback submit(string);\n    callback quit();\n}","handlingStrategy":"validation","validationCode":"# Before instantiating, assert every @slint.callback async method exists in the loaded globals\nclass App(slint.Component):\n    @slint.callback\n    async def quit(self): ...\n\nnames = {n.replace(\"-\", \"_\") for n in dir(App)}  # extend with your globals' callbacks\ndeclared = {c.replace(\"-\", \"_\") for g in app_globals for c in compdef.global_callbacks(g)}\nmissing = names - declared\nif missing: raise SystemExit(f\"Callbacks not declared in .slint: {missing}\")","typeGuard":null,"tryCatchPattern":"try:\n    app = App()\nexcept AttributeError as e:\n    raise SystemExit(f\"@slint.callback name mismatch: {e} — declare the callback in the global and keep names in sync\") from e","preventionTips":["Declare the callback in the global before writing the Python handler.","Keep one source of truth for names; regenerate/reload after .slint edits (re-run slint.load_file).","Remember dashes in Slint names map to underscores in Python."],"tags":["python","slint","callbacks","async","decorator","globals"],"backgroundTag":"undeclared-callback-binding","analyzedSha":"a9ea814a5813e7460fa1a867924872095a4d678d","analyzedAt":"2026-08-16T22:39:12.830Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}