mirror of
https://github.com/esphome/esphome.git
synced 2025-09-06 05:12:21 +01:00
Check lambdas for return statement (#539)
This commit is contained in:
@@ -333,7 +333,7 @@ def templatable(other_validators):
|
||||
|
||||
def validator(value):
|
||||
if isinstance(value, Lambda):
|
||||
return lambda_(value)
|
||||
return returning_lambda(value)
|
||||
if isinstance(other_validators, dict):
|
||||
return schema(value)
|
||||
return schema(value)
|
||||
@@ -974,6 +974,20 @@ def lambda_(value):
|
||||
return value
|
||||
|
||||
|
||||
def returning_lambda(value):
|
||||
"""Coerce this configuration option to a lambda.
|
||||
|
||||
Additionally, make sure the lambda returns something.
|
||||
"""
|
||||
value = lambda_(value)
|
||||
if u'return' not in value.value:
|
||||
raise Invalid("Lambda doesn't contain a 'return' statement, but the lambda "
|
||||
"is expected to return a value. \n"
|
||||
"Please make sure the lambda contains at least one "
|
||||
"return statement.")
|
||||
return value
|
||||
|
||||
|
||||
def dimensions(value):
|
||||
if isinstance(value, list):
|
||||
if len(value) != 2:
|
||||
|
Reference in New Issue
Block a user