Drop unnecessary lambdas in the entity filter (#122941)

This commit is contained in:
J. Nick Koston 2024-07-31 13:44:47 -05:00 committed by GitHub
parent 79a741486c
commit 2f3f124aa1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,7 +4,8 @@ from __future__ import annotations
from collections.abc import Callable from collections.abc import Callable
import fnmatch import fnmatch
from functools import lru_cache from functools import lru_cache, partial
import operator
import re import re
import voluptuous as vol import voluptuous as vol
@ -195,7 +196,7 @@ def _generate_filter_from_sets_and_pattern_lists(
# Case 1 - No filter # Case 1 - No filter
# - All entities included # - All entities included
if not have_include and not have_exclude: if not have_include and not have_exclude:
return lambda entity_id: True return bool
# Case 2 - Only includes # Case 2 - Only includes
# - Entity listed in entities include: include # - Entity listed in entities include: include
@ -280,4 +281,4 @@ def _generate_filter_from_sets_and_pattern_lists(
# Case 6 - No Domain and/or glob includes or excludes # Case 6 - No Domain and/or glob includes or excludes
# - Entity listed in entities include: include # - Entity listed in entities include: include
# - Otherwise: exclude # - Otherwise: exclude
return lambda entity_id: entity_id in include_e return partial(operator.contains, include_e)