Python: run mypy on the tests

This commit is contained in:
Simon Hausmann 2025-02-12 16:28:26 +01:00 committed by Simon Hausmann
parent c111098e49
commit 607d70b3fa
21 changed files with 169 additions and 69 deletions

View file

@ -4,9 +4,10 @@
from slint import slint as native
import weakref
import gc
import typing
def test_callback_gc():
def test_callback_gc() -> None:
compiler = native.Compiler()
compdef = compiler.build_from_source("""
@ -17,17 +18,18 @@ def test_callback_gc():
""", "").component("Test")
assert compdef != None
instance = compdef.create()
instance: native.ComponentInstance | None = compdef.create()
assert instance != None
class Handler:
def __init__(self, instance):
def __init__(self, instance: native.ComponentInstance) -> None:
self.instance = instance
def python_callback(self, input):
return input + instance.get_property("test-value")
def python_callback(self, input: str) -> str:
return input + typing.cast(str, self.instance.get_property("test-value"))
handler = Handler(instance)
handler: Handler | None = Handler(instance)
assert handler is not None
instance.set_callback(
"test-callback", handler.python_callback)
handler = None