Update mypy to 1.4.0 (#94987)

This commit is contained in:
Marc Mueller 2023-06-21 16:12:51 +02:00 committed by GitHub
parent c8cd469c95
commit 86792fcc2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 31 additions and 35 deletions

View File

@ -71,7 +71,7 @@ async def async_attach_trigger(
job, job,
{ {
"trigger": { "trigger": {
**trigger_data, # type: ignore[arg-type] # https://github.com/python/mypy/issues/9117 **trigger_data,
**config, **config,
"description": f"{DOMAIN} - {entity_id}", "description": f"{DOMAIN} - {entity_id}",
} }

View File

@ -78,7 +78,7 @@ class DemoMailbox(Mailbox):
"""Return a list of the current messages.""" """Return a list of the current messages."""
return sorted( return sorted(
self._messages.values(), self._messages.values(),
key=lambda item: item["info"]["origtime"], # type: ignore[no-any-return] key=lambda item: item["info"]["origtime"],
reverse=True, reverse=True,
) )

View File

@ -28,10 +28,10 @@ class DomainData:
_entry_datas: dict[str, RuntimeEntryData] = field(default_factory=dict) _entry_datas: dict[str, RuntimeEntryData] = field(default_factory=dict)
_stores: dict[str, Store] = field(default_factory=dict) _stores: dict[str, Store] = field(default_factory=dict)
_gatt_services_cache: MutableMapping[int, BleakGATTServiceCollection] = field( _gatt_services_cache: MutableMapping[int, BleakGATTServiceCollection] = field(
default_factory=lambda: LRU(MAX_CACHED_SERVICES) # type: ignore[no-any-return] default_factory=lambda: LRU(MAX_CACHED_SERVICES)
) )
_gatt_mtu_cache: MutableMapping[int, int] = field( _gatt_mtu_cache: MutableMapping[int, int] = field(
default_factory=lambda: LRU(MAX_CACHED_SERVICES) # type: ignore[no-any-return] default_factory=lambda: LRU(MAX_CACHED_SERVICES)
) )
def get_gatt_services_cache( def get_gatt_services_cache(

View File

@ -42,8 +42,8 @@ BINARY_SENSOR_TYPES: Final[tuple[FritzBinarySensorEntityDescription, ...]] = (
key="alarm", key="alarm",
translation_key="alarm", translation_key="alarm",
device_class=BinarySensorDeviceClass.WINDOW, device_class=BinarySensorDeviceClass.WINDOW,
suitable=lambda device: device.has_alarm, # type: ignore[no-any-return] suitable=lambda device: device.has_alarm,
is_on=lambda device: device.alert_state, # type: ignore[no-any-return] is_on=lambda device: device.alert_state,
), ),
FritzBinarySensorEntityDescription( FritzBinarySensorEntityDescription(
key="lock", key="lock",

View File

@ -97,7 +97,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
suitable=suitable_temperature, suitable=suitable_temperature,
native_value=lambda device: device.temperature, # type: ignore[no-any-return] native_value=lambda device: device.temperature,
), ),
FritzSensorEntityDescription( FritzSensorEntityDescription(
key="humidity", key="humidity",
@ -106,7 +106,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
device_class=SensorDeviceClass.HUMIDITY, device_class=SensorDeviceClass.HUMIDITY,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
suitable=lambda device: device.rel_humidity is not None, suitable=lambda device: device.rel_humidity is not None,
native_value=lambda device: device.rel_humidity, # type: ignore[no-any-return] native_value=lambda device: device.rel_humidity,
), ),
FritzSensorEntityDescription( FritzSensorEntityDescription(
key="battery", key="battery",
@ -115,7 +115,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
device_class=SensorDeviceClass.BATTERY, device_class=SensorDeviceClass.BATTERY,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
suitable=lambda device: device.battery_level is not None, suitable=lambda device: device.battery_level is not None,
native_value=lambda device: device.battery_level, # type: ignore[no-any-return] native_value=lambda device: device.battery_level,
), ),
FritzSensorEntityDescription( FritzSensorEntityDescription(
key="power_consumption", key="power_consumption",
@ -123,7 +123,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfPower.WATT, native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
suitable=lambda device: device.has_powermeter, # type: ignore[no-any-return] suitable=lambda device: device.has_powermeter,
native_value=lambda device: round((device.power or 0.0) / 1000, 3), native_value=lambda device: round((device.power or 0.0) / 1000, 3),
), ),
FritzSensorEntityDescription( FritzSensorEntityDescription(
@ -132,7 +132,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfElectricPotential.VOLT, native_unit_of_measurement=UnitOfElectricPotential.VOLT,
device_class=SensorDeviceClass.VOLTAGE, device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
suitable=lambda device: device.has_powermeter, # type: ignore[no-any-return] suitable=lambda device: device.has_powermeter,
native_value=lambda device: round((device.voltage or 0.0) / 1000, 2), native_value=lambda device: round((device.voltage or 0.0) / 1000, 2),
), ),
FritzSensorEntityDescription( FritzSensorEntityDescription(
@ -141,7 +141,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE, native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
device_class=SensorDeviceClass.CURRENT, device_class=SensorDeviceClass.CURRENT,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
suitable=lambda device: device.has_powermeter, # type: ignore[no-any-return] suitable=lambda device: device.has_powermeter,
native_value=lambda device: round((device.current or 0.0) / 1000, 3), native_value=lambda device: round((device.current or 0.0) / 1000, 3),
), ),
FritzSensorEntityDescription( FritzSensorEntityDescription(
@ -150,7 +150,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
suitable=lambda device: device.has_powermeter, # type: ignore[no-any-return] suitable=lambda device: device.has_powermeter,
native_value=lambda device: (device.energy or 0.0) / 1000, native_value=lambda device: (device.energy or 0.0) / 1000,
), ),
# Thermostat Sensors # Thermostat Sensors
@ -161,7 +161,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
suitable=suitable_comfort_temperature, suitable=suitable_comfort_temperature,
native_value=lambda device: device.comfort_temperature, # type: ignore[no-any-return] native_value=lambda device: device.comfort_temperature,
), ),
FritzSensorEntityDescription( FritzSensorEntityDescription(
key="eco_temperature", key="eco_temperature",
@ -170,7 +170,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
suitable=suitable_eco_temperature, suitable=suitable_eco_temperature,
native_value=lambda device: device.eco_temperature, # type: ignore[no-any-return] native_value=lambda device: device.eco_temperature,
), ),
FritzSensorEntityDescription( FritzSensorEntityDescription(
key="nextchange_temperature", key="nextchange_temperature",
@ -179,7 +179,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
suitable=suitable_nextchange_temperature, suitable=suitable_nextchange_temperature,
native_value=lambda device: device.nextchange_temperature, # type: ignore[no-any-return] native_value=lambda device: device.nextchange_temperature,
), ),
FritzSensorEntityDescription( FritzSensorEntityDescription(
key="nextchange_time", key="nextchange_time",

View File

@ -189,7 +189,7 @@ class JellyfinSource(MediaSource):
async def _build_artists(self, library_id: str) -> list[BrowseMediaSource]: async def _build_artists(self, library_id: str) -> list[BrowseMediaSource]:
"""Return all artists in the music library.""" """Return all artists in the music library."""
artists = await self._get_children(library_id, ITEM_TYPE_ARTIST) artists = await self._get_children(library_id, ITEM_TYPE_ARTIST)
artists = sorted(artists, key=lambda k: k[ITEM_KEY_NAME]) # type: ignore[no-any-return] artists = sorted(artists, key=lambda k: k[ITEM_KEY_NAME])
return [await self._build_artist(artist, False) for artist in artists] return [await self._build_artist(artist, False) for artist in artists]
async def _build_artist( async def _build_artist(
@ -220,7 +220,7 @@ class JellyfinSource(MediaSource):
async def _build_albums(self, parent_id: str) -> list[BrowseMediaSource]: async def _build_albums(self, parent_id: str) -> list[BrowseMediaSource]:
"""Return all albums of a single artist as browsable media sources.""" """Return all albums of a single artist as browsable media sources."""
albums = await self._get_children(parent_id, ITEM_TYPE_ALBUM) albums = await self._get_children(parent_id, ITEM_TYPE_ALBUM)
albums = sorted(albums, key=lambda k: k[ITEM_KEY_NAME]) # type: ignore[no-any-return] albums = sorted(albums, key=lambda k: k[ITEM_KEY_NAME])
return [await self._build_album(album, False) for album in albums] return [await self._build_album(album, False) for album in albums]
async def _build_album( async def _build_album(
@ -310,7 +310,7 @@ class JellyfinSource(MediaSource):
async def _build_movies(self, library_id: str) -> list[BrowseMediaSource]: async def _build_movies(self, library_id: str) -> list[BrowseMediaSource]:
"""Return all movies in the movie library.""" """Return all movies in the movie library."""
movies = await self._get_children(library_id, ITEM_TYPE_MOVIE) movies = await self._get_children(library_id, ITEM_TYPE_MOVIE)
movies = sorted(movies, key=lambda k: k[ITEM_KEY_NAME]) # type: ignore[no-any-return] movies = sorted(movies, key=lambda k: k[ITEM_KEY_NAME])
return [ return [
self._build_movie(movie) self._build_movie(movie)
for movie in movies for movie in movies
@ -363,7 +363,7 @@ class JellyfinSource(MediaSource):
async def _build_tvshow(self, library_id: str) -> list[BrowseMediaSource]: async def _build_tvshow(self, library_id: str) -> list[BrowseMediaSource]:
"""Return all series in the tv library.""" """Return all series in the tv library."""
series = await self._get_children(library_id, ITEM_TYPE_SERIES) series = await self._get_children(library_id, ITEM_TYPE_SERIES)
series = sorted(series, key=lambda k: k[ITEM_KEY_NAME]) # type: ignore[no-any-return] series = sorted(series, key=lambda k: k[ITEM_KEY_NAME])
return [await self._build_series(serie, False) for serie in series] return [await self._build_series(serie, False) for serie in series]
async def _build_series( async def _build_series(
@ -394,7 +394,7 @@ class JellyfinSource(MediaSource):
async def _build_seasons(self, series_id: str) -> list[BrowseMediaSource]: async def _build_seasons(self, series_id: str) -> list[BrowseMediaSource]:
"""Return all seasons in the series.""" """Return all seasons in the series."""
seasons = await self._get_children(series_id, ITEM_TYPE_SEASON) seasons = await self._get_children(series_id, ITEM_TYPE_SEASON)
seasons = sorted(seasons, key=lambda k: k[ITEM_KEY_NAME]) # type: ignore[no-any-return] seasons = sorted(seasons, key=lambda k: k[ITEM_KEY_NAME])
return [await self._build_season(season, False) for season in seasons] return [await self._build_season(season, False) for season in seasons]
async def _build_season( async def _build_season(
@ -425,7 +425,7 @@ class JellyfinSource(MediaSource):
async def _build_episodes(self, season_id: str) -> list[BrowseMediaSource]: async def _build_episodes(self, season_id: str) -> list[BrowseMediaSource]:
"""Return all episode in the season.""" """Return all episode in the season."""
episodes = await self._get_children(season_id, ITEM_TYPE_EPISODE) episodes = await self._get_children(season_id, ITEM_TYPE_EPISODE)
episodes = sorted(episodes, key=lambda k: k[ITEM_KEY_NAME]) # type: ignore[no-any-return] episodes = sorted(episodes, key=lambda k: k[ITEM_KEY_NAME])
return [ return [
self._build_episode(episode) self._build_episode(episode)
for episode in episodes for episode in episodes

View File

@ -71,7 +71,7 @@ SYSTEM_ENTITY_DESCRIPTIONS = (
device_class=SensorDeviceClass.ENUM, device_class=SensorDeviceClass.ENUM,
options=[opt.value for opt in XknxConnectionType], options=[opt.value for opt in XknxConnectionType],
should_poll=False, should_poll=False,
value_fn=lambda knx: knx.xknx.connection_manager.connection_type.value, # type: ignore[no-any-return] value_fn=lambda knx: knx.xknx.connection_manager.connection_type.value,
), ),
KNXSystemEntityDescription( KNXSystemEntityDescription(
key="telegrams_incoming", key="telegrams_incoming",

View File

@ -93,7 +93,7 @@ def setup_platform(
_LOGGER.warning("Unable to open serial port: %s", exc) _LOGGER.warning("Unable to open serial port: %s", exc)
return return
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, lambda event: lacrosse.close()) # type: ignore[no-any-return] hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, lambda event: lacrosse.close())
if CONF_JEELINK_LED in config: if CONF_JEELINK_LED in config:
lacrosse.led_mode_state(config.get(CONF_JEELINK_LED)) lacrosse.led_mode_state(config.get(CONF_JEELINK_LED))

View File

@ -63,7 +63,7 @@ async def async_attach_trigger(
job, job,
{ {
"trigger": { "trigger": {
**trigger_data, # type: ignore[arg-type] # https://github.com/python/mypy/issues/9117 **trigger_data,
"platform": "persistent_notification", "platform": "persistent_notification",
"update_type": update_type, "update_type": update_type,
"notification": notification, "notification": notification,

View File

@ -6,7 +6,7 @@ from collections.abc import Coroutine
import contextlib import contextlib
from datetime import timedelta from datetime import timedelta
import logging import logging
from typing import Any, cast from typing import Any
import httpx import httpx
import voluptuous as vol import voluptuous as vol
@ -160,11 +160,7 @@ def _rest_coordinator(
if resource_template: if resource_template:
async def _async_refresh_with_resource_template() -> None: async def _async_refresh_with_resource_template() -> None:
rest.set_url( rest.set_url(resource_template.async_render(parse_result=False))
cast(template.Template, resource_template).async_render(
parse_result=False
)
)
await rest.async_update() await rest.async_update()
update_method = _async_refresh_with_resource_template update_method = _async_refresh_with_resource_template

View File

@ -206,7 +206,7 @@ def process_before_send(
"channel": channel, "channel": channel,
"custom_components": "\n".join(sorted(custom_components)), "custom_components": "\n".join(sorted(custom_components)),
"integrations": "\n".join(sorted(integrations)), "integrations": "\n".join(sorted(integrations)),
**system_info, # type: ignore[arg-type] **system_info,
}, },
} }
) )

View File

@ -155,7 +155,7 @@ def _async_device_as_dict(hass: HomeAssistant, device: TuyaDevice) -> dict[str,
for entity_entry in hass_entities: for entity_entry in hass_entities:
state = hass.states.get(entity_entry.entity_id) state = hass.states.get(entity_entry.entity_id)
state_dict = None state_dict: dict[str, Any] | None = None
if state: if state:
state_dict = dict(state.as_dict()) state_dict = dict(state.as_dict())

View File

@ -38,7 +38,7 @@ def singleton(data_key: str) -> Callable[[_FuncType[_T]], _FuncType[_T]]:
async def async_wrapped(hass: HomeAssistant) -> Any: async def async_wrapped(hass: HomeAssistant) -> Any:
if data_key not in hass.data: if data_key not in hass.data:
evt = hass.data[data_key] = asyncio.Event() evt = hass.data[data_key] = asyncio.Event()
result = await func(hass) # type: ignore[misc] result = await func(hass)
hass.data[data_key] = result hass.data[data_key] = result
evt.set() evt.set()
return cast(_T, result) return cast(_T, result)

View File

@ -11,7 +11,7 @@ astroid==2.15.4
coverage==7.2.4 coverage==7.2.4
freezegun==1.2.2 freezegun==1.2.2
mock-open==1.4.0 mock-open==1.4.0
mypy==1.3.0 mypy==1.4.0
pre-commit==3.1.0 pre-commit==3.1.0
pydantic==1.10.9 pydantic==1.10.9
pylint==2.17.4 pylint==2.17.4