Skip to content

Commit 6f7857d

Browse files
committed
Make mypy happy
1 parent c5e43f5 commit 6f7857d

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

api/python/slint/slint/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
PyStruct,
3131
Timer,
3232
TimerMode,
33+
)
34+
from .core import (
3335
init_translations as _slint_init_translations,
3436
)
3537
from .loop import SlintEventLoop

api/python/slint/slint/codegen/emitters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def init_stub() -> cst.FunctionDef:
369369
path.write_text(module.code, encoding="utf-8")
370370

371371

372-
def format_callable_annotation(callback: "CallbackMeta") -> str: # type: ignore[name-defined]
372+
def format_callable_annotation(callback: "CallbackMeta") -> str:
373373
args = callback.arg_types
374374
return_type = callback.return_type
375375

api/python/slint/slint/codegen/generator.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from pathlib import Path
88
from typing import TYPE_CHECKING, Iterable
99

10-
from .. import core
1110
from ..api import _normalize_prop
11+
from ..core import Brush, CompilationResult, Compiler, DiagnosticLevel, Image
1212
from .emitters import write_python_module, write_stub_module
1313
from .models import (
1414
CallbackMeta,
@@ -41,7 +41,8 @@ def generate_project(
4141
if output_dir is not None:
4242
output_dir.mkdir(parents=True, exist_ok=True)
4343

44-
compiler = core.Compiler()
44+
compiler = Compiler()
45+
4546
if config.style:
4647
compiler.style = config.style
4748
if config.include_paths:
@@ -101,23 +102,23 @@ def _discover_slint_files(inputs: Iterable[Path]) -> Iterable[tuple[Path, Path]]
101102

102103

103104
def _compile_slint(
104-
compiler: core.Compiler,
105+
compiler: Compiler,
105106
source_path: Path,
106107
config: GenerationConfig,
107-
) -> core.CompilationResult | None:
108+
) -> CompilationResult | None:
108109
result = compiler.build_from_path(source_path)
109110

110-
diagnostics = result.diagnostics
111-
diagnostic_error = getattr(core, "DiagnosticLevel", None)
112-
error_enum = getattr(diagnostic_error, "Error", None)
113-
114111
def is_error(diag: PyDiagnostic) -> bool:
115-
if error_enum is not None:
116-
return diag.level == error_enum
117-
return str(diag.level).lower().startswith("error")
112+
return diag.level == DiagnosticLevel.Error
118113

119-
errors = [diag for diag in diagnostics if is_error(diag)]
120-
warnings = [diag for diag in diagnostics if not is_error(diag)]
114+
errors: list[PyDiagnostic] = []
115+
warnings: list[PyDiagnostic] = []
116+
117+
for diag in result.diagnostics:
118+
if is_error(diag):
119+
errors.append(diag)
120+
else:
121+
warnings.append(diag)
121122

122123
if warnings and not config.quiet:
123124
for diag in warnings:
@@ -132,8 +133,9 @@ def is_error(diag: PyDiagnostic) -> bool:
132133
return result
133134

134135

135-
def _collect_metadata(result: core.CompilationResult) -> ModuleArtifacts:
136+
def _collect_metadata(result: CompilationResult) -> ModuleArtifacts:
136137
components: list[ComponentMeta] = []
138+
137139
for name in result.component_names:
138140
comp = result.component(name)
139141

@@ -274,9 +276,9 @@ def _python_value_hint(value: object) -> str:
274276
return "float"
275277
if isinstance(value, str):
276278
return "str"
277-
if isinstance(value, core.Image):
279+
if isinstance(value, Image):
278280
return "slint.Image"
279-
if isinstance(value, core.Brush):
281+
if isinstance(value, Brush):
280282
return "slint.Brush"
281283
return "Any"
282284

0 commit comments

Comments
 (0)