mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Cache try_parse_enum (#87911)
This commit is contained in:
parent
6680e819e5
commit
7aa1359c4a
@ -1,11 +1,23 @@
|
|||||||
"""Helpers for working with enums."""
|
"""Helpers for working with enums."""
|
||||||
|
from collections.abc import Callable
|
||||||
import contextlib
|
import contextlib
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, TypeVar
|
from typing import TYPE_CHECKING, Any, TypeVar
|
||||||
|
|
||||||
|
# https://github.com/python/mypy/issues/5107
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
_LruCacheT = TypeVar("_LruCacheT", bound=Callable)
|
||||||
|
|
||||||
|
def lru_cache(func: _LruCacheT) -> _LruCacheT:
|
||||||
|
"""Stub for lru_cache."""
|
||||||
|
|
||||||
|
else:
|
||||||
|
from functools import lru_cache
|
||||||
|
|
||||||
_EnumT = TypeVar("_EnumT", bound=Enum)
|
_EnumT = TypeVar("_EnumT", bound=Enum)
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache
|
||||||
def try_parse_enum(cls: type[_EnumT], value: Any) -> _EnumT | None:
|
def try_parse_enum(cls: type[_EnumT], value: Any) -> _EnumT | None:
|
||||||
"""Try to parse the value into an Enum.
|
"""Try to parse the value into an Enum.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user