[lvgl] Add return-type annotations to lazy schema helpers

_lazy_update_schema, container_schema, and their inner build() /
validator() closures all returned untyped functions. Annotate them so
callers see Callable[[Any], Any] for the validator factories and Schema
for the inner builds.
This commit is contained in:
J. Nick Koston
2026-05-16 17:03:19 -07:00
parent c062c1ddbd
commit 2159c53c9f
2 changed files with 8 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
from collections.abc import Callable
from typing import Any
from esphome import config_validation as cv
from esphome.automation import Trigger, validate_automation
@@ -534,7 +535,7 @@ def strip_defaults(schema: cv.Schema):
return cv.Schema({cv.Optional(k): v for k, v in schema.schema.items()})
def container_schema(widget_type: WidgetType, extras=None):
def container_schema(widget_type: WidgetType, extras=None) -> Callable[[Any], Any]:
"""
Create a schema for a container widget of a given type. All obj properties are available, plus
the extras passed in, plus any defined for the specific widget being specified.
@@ -558,7 +559,7 @@ def container_schema(widget_type: WidgetType, extras=None):
get_schema = lazy_once(build)
def validator(value):
def validator(value: Any) -> Any:
value = value or {}
return append_layout_schema(get_schema(), value)(value)

View File

@@ -1,4 +1,6 @@
from collections.abc import Callable
import sys
from typing import Any
from esphome import codegen as cg, config_validation as cv
from esphome.automation import register_action
@@ -74,7 +76,7 @@ from ..types import (
EVENT_LAMB = "event_lamb__"
def _lazy_update_schema(widget_type: "WidgetType"):
def _lazy_update_schema(widget_type: "WidgetType") -> Callable[[Any], Any]:
"""Defer construction of a widget's update-action schema until first use.
base_update_schema(...).extend(widget_type.modify_schema) compiles several
@@ -87,7 +89,7 @@ def _lazy_update_schema(widget_type: "WidgetType"):
level would deadlock the import.
"""
def build():
def build() -> Schema:
from ..schemas import base_update_schema
return base_update_schema(widget_type, widget_type.parts).extend(
@@ -96,7 +98,7 @@ def _lazy_update_schema(widget_type: "WidgetType"):
get_schema = lazy_once(build)
def validator(value):
def validator(value: Any) -> Any:
return get_schema()(value)
return validator