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

View File

@ -47,7 +47,7 @@ from .const import (
) )
_DlnaDmsDeviceMethod = TypeVar("_DlnaDmsDeviceMethod", bound="DmsDeviceSource") _DlnaDmsDeviceMethod = TypeVar("_DlnaDmsDeviceMethod", bound="DmsDeviceSource")
_RetType = TypeVar("_RetType") _R = TypeVar("_R")
class DlnaDmsData: class DlnaDmsData:
@ -167,12 +167,12 @@ class ActionError(DlnaDmsDeviceError):
def catch_request_errors( def catch_request_errors(
func: Callable[[_DlnaDmsDeviceMethod, str], Coroutine[Any, Any, _RetType]] func: Callable[[_DlnaDmsDeviceMethod, str], Coroutine[Any, Any, _R]]
) -> Callable[[_DlnaDmsDeviceMethod, str], Coroutine[Any, Any, _RetType]]: ) -> Callable[[_DlnaDmsDeviceMethod, str], Coroutine[Any, Any, _R]]:
"""Catch UpnpError errors.""" """Catch UpnpError errors."""
@functools.wraps(func) @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.""" """Catch UpnpError errors and check availability before and after request."""
if not self.available: if not self.available:
LOGGER.warning("Device disappeared when trying to call %s", func.__name__) 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__) _LOGGER: Final = logging.getLogger(__name__)
PLATFORMS: Final = [Platform.SENSOR] PLATFORMS: Final = [Platform.SENSOR]
FroniusCoordinatorType = TypeVar("FroniusCoordinatorType", bound=FroniusCoordinatorBase) _FroniusCoordinatorT = TypeVar("_FroniusCoordinatorT", bound=FroniusCoordinatorBase)
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
@ -199,8 +199,8 @@ class FroniusSolarNet:
@staticmethod @staticmethod
async def _init_optional_coordinator( async def _init_optional_coordinator(
coordinator: FroniusCoordinatorType, coordinator: _FroniusCoordinatorT,
) -> FroniusCoordinatorType | None: ) -> _FroniusCoordinatorT | None:
"""Initialize an update coordinator and return it if devices are found.""" """Initialize an update coordinator and return it if devices are found."""
try: try:
await coordinator.async_config_entry_first_refresh() await coordinator.async_config_entry_first_refresh()

View File

@ -31,7 +31,7 @@ if TYPE_CHECKING:
from . import FroniusSolarNet from . import FroniusSolarNet
from .sensor import _FroniusSensorEntity from .sensor import _FroniusSensorEntity
FroniusEntityType = TypeVar("FroniusEntityType", bound=_FroniusSensorEntity) _FroniusEntityT = TypeVar("_FroniusEntityT", bound=_FroniusSensorEntity)
class FroniusCoordinatorBase( class FroniusCoordinatorBase(
@ -84,7 +84,7 @@ class FroniusCoordinatorBase(
def add_entities_for_seen_keys( def add_entities_for_seen_keys(
self, self,
async_add_entities: AddEntitiesCallback, async_add_entities: AddEntitiesCallback,
entity_constructor: type[FroniusEntityType], entity_constructor: type[_FroniusEntityT],
) -> None: ) -> None:
""" """
Add entities for received keys and registers listener for future seen keys. 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.""" """Representation of a Vera device entity."""
def __init__( def __init__(
self, vera_device: DeviceType, controller_data: ControllerData self, vera_device: _DeviceTypeT, controller_data: ControllerData
) -> None: ) -> None:
"""Initialize the device.""" """Initialize the device."""
self.vera_device = vera_device self.vera_device = vera_device
@ -242,7 +242,7 @@ class VeraDevice(Generic[DeviceType], Entity):
"""Subscribe to updates.""" """Subscribe to updates."""
self.controller.register(self.vera_device, self._update_callback) 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.""" """Update the state."""
self.schedule_update_ha_state(True) 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] ApiResult = Callable[[dict[str, Any]], None]
ComponentSetup = Callable[[], Awaitable[bool]] ComponentSetup = Callable[[], Awaitable[bool]]
T = TypeVar("T") _T = TypeVar("_T")
YieldFixture = Generator[T, None, None] YieldFixture = Generator[_T, None, None]
CALENDAR_ID = "qwertyuiopasdfghjklzxcvbnm@import.calendar.google.com" CALENDAR_ID = "qwertyuiopasdfghjklzxcvbnm@import.calendar.google.com"

View File

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

View File

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