Skip to content

Commit dbe2c59

Browse files
committed
Python: Fix support for underscores in async callback decorators
Fixes #10024
1 parent 571e549 commit dbe2c59

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

api/python/slint/interpreter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ impl ComponentDefinition {
307307
self.definition
308308
.properties_and_callbacks()
309309
.find_map(|(name, (ty, _))| {
310-
if name == callback_name {
310+
if normalize_identifier(&name) == callback_name {
311311
if let Type::Callback(signature) = ty {
312312
return Some(signature.return_type == Type::Void);
313313
}
@@ -324,7 +324,7 @@ impl ComponentDefinition {
324324
.global_properties_and_callbacks(&global_name)
325325
.and_then(|mut props| {
326326
props.find_map(|(name, (ty, _))| {
327-
if name == callback_name {
327+
if normalize_identifier(&name) == callback_name {
328328
if let Type::Callback(signature) = ty {
329329
return Some(signature.return_type == Type::Void);
330330
}

api/python/slint/tests/test-load-file.slint

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ export component App inherits Window {
5555
call-void();
5656
}
5757
callback call-void();
58+
callback invoke-call-void2();
59+
invoke-call-void2 => {
60+
call_void2();
61+
}
62+
callback call_void2();
5863

5964
in-out property <TestEnum> enum-property: TestEnum.Variant2;
6065
in-out property <[TestEnum]> model-with-enums: [TestEnum.Variant2, TestEnum.Variant1];

api/python/slint/tests/test_callback_decorators.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,20 @@ async def call_void(self) -> None:
5454
value = await self.in_queue.get()
5555
await self.out_queue.put(value + 1)
5656

57+
@slint.callback()
58+
async def call_void2(self) -> None:
59+
value = await self.in_queue.get()
60+
await self.out_queue.put(value + 2)
61+
5762
async def main(
5863
instance: SubClass, in_queue: asyncio.Queue[int], out_queue: asyncio.Queue[int]
5964
) -> None:
6065
await in_queue.put(42)
6166
instance.invoke_call_void()
6267
assert await out_queue.get() == 43
68+
await in_queue.put(43)
69+
instance.invoke_call_void2()
70+
assert await out_queue.get() == 45
6371
slint.quit_event_loop()
6472

6573
in_queue: asyncio.Queue[int] = asyncio.Queue()

0 commit comments

Comments
 (0)