From 7e0216e1bff63ac5a6073a8b27743427b21ff349 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 6 Apr 2026 18:45:08 -1000 Subject: [PATCH] [core] Add type annotations to cv.ByteLength --- esphome/config_validation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esphome/config_validation.py b/esphome/config_validation.py index cbf81de1478..7805de98db7 100644 --- a/esphome/config_validation.py +++ b/esphome/config_validation.py @@ -131,14 +131,14 @@ RequiredFieldInvalid = vol.RequiredFieldInvalid ROOT_CONFIG_PATH = object() -def ByteLength(*, max: int): +def ByteLength(*, max: int) -> Callable[[str], str]: """Validate that the UTF-8 byte length of a string does not exceed max. Use instead of Length() when the limit must apply to encoded bytes, not characters (e.g. for protobuf length-varint constraints). """ - def validator(value): + def validator(value: str) -> str: byte_len = len(str(value).encode("utf-8")) if byte_len > max: raise Invalid(