Make TypeVars private (3) (#68207)

This commit is contained in:
Marc Mueller 2022-03-17 19:11:14 +01:00 committed by GitHub
parent eae0c75620
commit 8f69d31322
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 26 additions and 26 deletions

View file

@ -52,19 +52,19 @@ def _retrieve_linked_keypad_battery_state(detail: KeypadDetail) -> int | None:
return detail.battery_percentage
T = TypeVar("T", LockDetail, KeypadDetail)
_T = TypeVar("_T", LockDetail, KeypadDetail)
@dataclass
class AugustRequiredKeysMixin(Generic[T]):
class AugustRequiredKeysMixin(Generic[_T]):
"""Mixin for required keys."""
value_fn: Callable[[T], int | None]
value_fn: Callable[[_T], int | None]
@dataclass
class AugustSensorEntityDescription(
SensorEntityDescription, AugustRequiredKeysMixin[T]
SensorEntityDescription, AugustRequiredKeysMixin[_T]
):
"""Describes August sensor entity."""
@ -255,10 +255,10 @@ class AugustOperatorSensor(AugustEntityMixin, RestoreEntity, SensorEntity):
return f"{self._device_id}_lock_operator"
class AugustBatterySensor(AugustEntityMixin, SensorEntity, Generic[T]):
class AugustBatterySensor(AugustEntityMixin, SensorEntity, Generic[_T]):
"""Representation of an August sensor."""
entity_description: AugustSensorEntityDescription[T]
entity_description: AugustSensorEntityDescription[_T]
_attr_device_class = SensorDeviceClass.BATTERY
_attr_native_unit_of_measurement = PERCENTAGE
@ -267,7 +267,7 @@ class AugustBatterySensor(AugustEntityMixin, SensorEntity, Generic[T]):
data: AugustData,
device,
old_device,
description: AugustSensorEntityDescription[T],
description: AugustSensorEntityDescription[_T],
):
"""Initialize the sensor."""
super().__init__(data, device)

View file

@ -47,7 +47,7 @@ from .const import (
)
_DlnaDmsDeviceMethod = TypeVar("_DlnaDmsDeviceMethod", bound="DmsDeviceSource")
_RetType = TypeVar("_RetType")
_R = TypeVar("_R")
class DlnaDmsData:
@ -167,12 +167,12 @@ class ActionError(DlnaDmsDeviceError):
def catch_request_errors(
func: Callable[[_DlnaDmsDeviceMethod, str], Coroutine[Any, Any, _RetType]]
) -> Callable[[_DlnaDmsDeviceMethod, str], Coroutine[Any, Any, _RetType]]:
func: Callable[[_DlnaDmsDeviceMethod, str], Coroutine[Any, Any, _R]]
) -> Callable[[_DlnaDmsDeviceMethod, str], Coroutine[Any, Any, _R]]:
"""Catch UpnpError errors."""
@functools.wraps(func)
async def wrapper(self: _DlnaDmsDeviceMethod, req_param: str) -> _RetType:
async def wrapper(self: _DlnaDmsDeviceMethod, req_param: str) -> _R:
"""Catch UpnpError errors and check availability before and after request."""
if not self.available:
LOGGER.warning("Device disappeared when trying to call %s", func.__name__)

View file

@ -30,7 +30,7 @@ from .coordinator import (
_LOGGER: Final = logging.getLogger(__name__)
PLATFORMS: Final = [Platform.SENSOR]
FroniusCoordinatorType = TypeVar("FroniusCoordinatorType", bound=FroniusCoordinatorBase)
_FroniusCoordinatorT = TypeVar("_FroniusCoordinatorT", bound=FroniusCoordinatorBase)
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
@ -199,8 +199,8 @@ class FroniusSolarNet:
@staticmethod
async def _init_optional_coordinator(
coordinator: FroniusCoordinatorType,
) -> FroniusCoordinatorType | None:
coordinator: _FroniusCoordinatorT,
) -> _FroniusCoordinatorT | None:
"""Initialize an update coordinator and return it if devices are found."""
try:
await coordinator.async_config_entry_first_refresh()

View file

@ -31,7 +31,7 @@ if TYPE_CHECKING:
from . import FroniusSolarNet
from .sensor import _FroniusSensorEntity
FroniusEntityType = TypeVar("FroniusEntityType", bound=_FroniusSensorEntity)
_FroniusEntityT = TypeVar("_FroniusEntityT", bound=_FroniusSensorEntity)
class FroniusCoordinatorBase(
@ -84,7 +84,7 @@ class FroniusCoordinatorBase(
def add_entities_for_seen_keys(
self,
async_add_entities: AddEntitiesCallback,
entity_constructor: type[FroniusEntityType],
entity_constructor: type[_FroniusEntityT],
) -> None:
"""
Add entities for received keys and registers listener for future seen keys.

View file

@ -214,14 +214,14 @@ def map_vera_device(
)
DeviceType = TypeVar("DeviceType", bound=veraApi.VeraDevice)
_DeviceTypeT = TypeVar("_DeviceTypeT", bound=veraApi.VeraDevice)
class VeraDevice(Generic[DeviceType], Entity):
class VeraDevice(Generic[_DeviceTypeT], Entity):
"""Representation of a Vera device entity."""
def __init__(
self, vera_device: DeviceType, controller_data: ControllerData
self, vera_device: _DeviceTypeT, controller_data: ControllerData
) -> None:
"""Initialize the device."""
self.vera_device = vera_device
@ -242,7 +242,7 @@ class VeraDevice(Generic[DeviceType], Entity):
"""Subscribe to updates."""
self.controller.register(self.vera_device, self._update_callback)
def _update_callback(self, _device: DeviceType) -> None:
def _update_callback(self, _device: _DeviceTypeT) -> None:
"""Update the state."""
self.schedule_update_ha_state(True)

View file

@ -24,8 +24,8 @@ ORIG_TIMEZONE = dt_util.DEFAULT_TIME_ZONE
ApiResult = Callable[[dict[str, Any]], None]
ComponentSetup = Callable[[], Awaitable[bool]]
T = TypeVar("T")
YieldFixture = Generator[T, None, None]
_T = TypeVar("_T")
YieldFixture = Generator[_T, None, None]
CALENDAR_ID = "qwertyuiopasdfghjklzxcvbnm@import.calendar.google.com"

View file

@ -22,8 +22,8 @@ from tests.common import MockConfigEntry
# Typing helpers
PlatformSetup = Callable[[], Awaitable[None]]
T = TypeVar("T")
YieldFixture = Generator[T, None, None]
_T = TypeVar("_T")
YieldFixture = Generator[_T, None, None]
PROJECT_ID = "some-project-id"
CLIENT_ID = "some-client-id"

View file

@ -24,8 +24,8 @@ CONFIG_ENTRY_DATA = {"server_url": SERVER_URL}
# Typing helpers
ComponentSetup = Callable[[], Awaitable[None]]
T = TypeVar("T")
YieldFixture = Generator[T, None, None]
_T = TypeVar("_T")
YieldFixture = Generator[_T, None, None]
@pytest.fixture(autouse=True)