slint-ui/slint · error · RuntimeError
Callback ' ' cannot be used with a callback decorator for…
Error message
Callback '${name}' cannot be used with a callback decorator for an async function, as it doesn't return void What it means
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.
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.
Example fix
# before (.slint)
callback validate() -> bool;
# Python
@slint.callback("validate")
async def validate(): return True # RuntimeError
# after (.slint)
property <bool> valid;
callback validate(); # async handler sets `valid` instead of returning Defensive patterns
Strategy: validation
Validate before calling
if asyncio.iscoroutinefunction(fn) and not comp.callback_returns_void(name):
raise TypeError(f"async handler for '{name}' requires a void callback") Type guard
def is_async_handler(fn):
return asyncio.iscoroutinefunction(fn) Try / catch
try:
component.validate = async_handler
except RuntimeError as e:
logging.error("use a sync handler or a void callback: %s", e) Prevention
- Declare callbacks used by async handlers as `callback name(args);` with no return type.
- Standardize on sync handlers for value-returning callbacks.
When it happens
Trigger: Applying @slint.callback("name") to an `async def` where the component declares `callback name(...) -> someType`.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Callback ' ' in global ' ' cannot be used with a callback…
- Callback ' ' cannot be used with a callback decorator for…
- Callback ' ' in global ' ' cannot be used with a callback…
- binding was of the wrong type
- Cannot invoke callback
AI-assisted analysis of slint-ui/slint@bb937076de (2026-09-16).
Data as JSON: /api/errors/d5587f746342e4cd.
Report an issue: GitHub.
Appendix: source
Thrown at api/python/slint/slint/__init__.py:192
is_void = compdef.global_callback_returns_void(
global_name, name
)
if is_void is None:
raise AttributeError(
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"
)
if not is_void:
raise RuntimeError(
f"Callback '{name}' in global '{global_name}' cannot be used with a callback decorator for an async function, as it doesn't return void"
)
else:
is_void = compdef.callback_returns_void(name)
if is_void is None:
raise AttributeError(
f"Callback '{name}' cannot be used with a callback decorator for an async function, as it is not declared in Slint component"
)
if not is_void:
raise RuntimeError(
f"Callback '{name}' cannot be used with a callback decorator for an async function, as it doesn't return void"
)
def mk_callback(
self: Any, callback: typing.Callable[..., Any]
) -> typing.Callable[..., Any]:
def invoke(*args: Any, **kwargs: Any) -> Any:
return callback(self, *args, **kwargs)
return invoke
if "global_name" in callback_info:
self.__instance__.set_global_callback(
callback_info["global_name"], name, mk_callback(self, value)
)
else:
self.__instance__.set_callback(name, mk_callback(self, value))
View on GitHub (pinned to bb937076de)