mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Add return type annotation to StrEnum (#60624)
This commit is contained in:
parent
ad75c217ce
commit
a90ef488a1
@ -2,13 +2,15 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any
|
from typing import Any, TypeVar
|
||||||
|
|
||||||
|
T = TypeVar("T", bound="StrEnum")
|
||||||
|
|
||||||
|
|
||||||
class StrEnum(str, Enum):
|
class StrEnum(str, Enum):
|
||||||
"""Partial backport of Python 3.11's StrEnum for our basic use cases."""
|
"""Partial backport of Python 3.11's StrEnum for our basic use cases."""
|
||||||
|
|
||||||
def __new__(cls, value: str, *args: Any, **kwargs: Any): # type: ignore[no-untyped-def]
|
def __new__(cls: type[T], value: str, *args: Any, **kwargs: Any) -> T:
|
||||||
"""Create a new StrEnum instance."""
|
"""Create a new StrEnum instance."""
|
||||||
if not isinstance(value, str):
|
if not isinstance(value, str):
|
||||||
raise TypeError(f"{value!r} is not a string")
|
raise TypeError(f"{value!r} is not a string")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user