From 0dddeea4d23a8e0d3ae7cccb6366ba4a102e5cad Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 7 Apr 2026 14:10:18 -1000 Subject: [PATCH] [core] Assert stateless capture in test, fix TemplatableFn comment --- esphome/cpp_generator.py | 2 +- tests/unit_tests/test_cpp_generator.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/esphome/cpp_generator.py b/esphome/cpp_generator.py index 55f49fcfa7..48b53b197a 100644 --- a/esphome/cpp_generator.py +++ b/esphome/cpp_generator.py @@ -845,7 +845,7 @@ async def templatable( if output_type is std_string: return FlashStringLiteral(value) # For non-string types, wrap constants in stateless lambdas so that - # TemplatableValue stores them as function pointers (4 bytes vs 8). + # TemplatableFn (used by TEMPLATABLE_VALUE macro) stores them as function pointers. if output_type is not None: from esphome.cpp_types import std_string diff --git a/tests/unit_tests/test_cpp_generator.py b/tests/unit_tests/test_cpp_generator.py index aef6d056b2..3c87e311c3 100644 --- a/tests/unit_tests/test_cpp_generator.py +++ b/tests/unit_tests/test_cpp_generator.py @@ -673,6 +673,7 @@ async def test_templatable__string_with_non_string_output_type() -> None: result = await cg.templatable("hello", [], ct.bool_) assert isinstance(result, cg.LambdaExpression) + assert result.capture == "" @pytest.mark.asyncio