diff --git a/homeassistant/backports/functools.py b/homeassistant/backports/functools.py index ddcbab7dfc0..83d66a39f71 100644 --- a/homeassistant/backports/functools.py +++ b/homeassistant/backports/functools.py @@ -6,22 +6,21 @@ from types import GenericAlias from typing import Any, Generic, Self, TypeVar, overload _T = TypeVar("_T") -_R = TypeVar("_R") -class cached_property(Generic[_T, _R]): # pylint: disable=invalid-name +class cached_property(Generic[_T]): # pylint: disable=invalid-name """Backport of Python 3.12's cached_property. Includes https://github.com/python/cpython/pull/101890/files """ - def __init__(self, func: Callable[[_T], _R]) -> None: + def __init__(self, func: Callable[[Any], _T]) -> None: """Initialize.""" - self.func = func - self.attrname: Any = None + self.func: Callable[[Any], _T] = func + self.attrname: str | None = None self.__doc__ = func.__doc__ - def __set_name__(self, owner: type[_T], name: str) -> None: + def __set_name__(self, owner: type[Any], name: str) -> None: """Set name.""" if self.attrname is None: self.attrname = name @@ -32,14 +31,16 @@ class cached_property(Generic[_T, _R]): # pylint: disable=invalid-name ) @overload - def __get__(self, instance: None, owner: type[_T]) -> Self: + def __get__(self, instance: None, owner: type[Any] | None = None) -> Self: ... @overload - def __get__(self, instance: _T, owner: type[_T]) -> _R: + def __get__(self, instance: Any, owner: type[Any] | None = None) -> _T: ... - def __get__(self, instance: _T | None, owner: type[_T] | None = None) -> _R | Self: + def __get__( + self, instance: Any | None, owner: type[Any] | None = None + ) -> _T | Self: """Get.""" if instance is None: return self