From 0c8eeaa6436b04ba6da46bccab8b11523f314d9b Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 8 Nov 2022 14:41:39 +0100 Subject: [PATCH] Update mypy to 0.990 (#81783) * Update mypy to 0.990 * Remove type ignore - overriding attr with property (13475) * Remove type ignores - hasattr (13544) * Adjust type ignore - assignment (13549) * New error code - type-abstract (13785) * Disable annotation-unchecked (13851) --- homeassistant/auth/__init__.py | 3 +-- homeassistant/auth/mfa_modules/__init__.py | 1 - homeassistant/auth/providers/__init__.py | 4 +--- homeassistant/components/climate/__init__.py | 4 ++-- homeassistant/components/knx/__init__.py | 4 ++-- homeassistant/components/knx/schema.py | 4 ++-- .../components/media_player/__init__.py | 16 ++++------------ homeassistant/components/notify/legacy.py | 2 +- homeassistant/components/recorder/models.py | 6 +++--- homeassistant/helpers/entity.py | 4 ++-- homeassistant/util/yaml/dumper.py | 4 +++- homeassistant/util/yaml/loader.py | 2 +- mypy.ini | 1 + requirements_test.txt | 2 +- script/hassfest/mypy_config.py | 3 ++- 15 files changed, 26 insertions(+), 34 deletions(-) diff --git a/homeassistant/auth/__init__.py b/homeassistant/auth/__init__.py index 12511a7f4a5..bbd23983e2b 100644 --- a/homeassistant/auth/__init__.py +++ b/homeassistant/auth/__init__.py @@ -356,8 +356,7 @@ class AuthManager: provider = self._async_get_auth_provider(credentials) if provider is not None and hasattr(provider, "async_will_remove_credentials"): - # https://github.com/python/mypy/issues/1424 - await provider.async_will_remove_credentials(credentials) # type: ignore[attr-defined] + await provider.async_will_remove_credentials(credentials) await self._store.async_remove_credentials(credentials) diff --git a/homeassistant/auth/mfa_modules/__init__.py b/homeassistant/auth/mfa_modules/__init__.py index 61c36da6e90..ebfe1332cd2 100644 --- a/homeassistant/auth/mfa_modules/__init__.py +++ b/homeassistant/auth/mfa_modules/__init__.py @@ -166,7 +166,6 @@ async def _load_mfa_module(hass: HomeAssistant, module_name: str) -> types.Modul processed = hass.data[DATA_REQS] = set() - # https://github.com/python/mypy/issues/1424 await requirements.async_process_requirements( hass, module_path, module.REQUIREMENTS ) diff --git a/homeassistant/auth/providers/__init__.py b/homeassistant/auth/providers/__init__.py index 6feb4b26759..2448225a284 100644 --- a/homeassistant/auth/providers/__init__.py +++ b/homeassistant/auth/providers/__init__.py @@ -250,9 +250,7 @@ class LoginFlow(data_entry_flow.FlowHandler): auth_module, "async_initialize_login_mfa_step" ): try: - await auth_module.async_initialize_login_mfa_step( # type: ignore[attr-defined] - self.user.id - ) + await auth_module.async_initialize_login_mfa_step(self.user.id) except HomeAssistantError: _LOGGER.exception("Error initializing MFA step") return self.async_abort(reason="unknown_error") diff --git a/homeassistant/components/climate/__init__.py b/homeassistant/components/climate/__init__.py index 67348d38625..be5f33f8cd5 100644 --- a/homeassistant/components/climate/__init__.py +++ b/homeassistant/components/climate/__init__.py @@ -531,7 +531,7 @@ class ClimateEntity(Entity): async def async_turn_on(self) -> None: """Turn the entity on.""" if hasattr(self, "turn_on"): - await self.hass.async_add_executor_job(self.turn_on) # type: ignore[attr-defined] + await self.hass.async_add_executor_job(self.turn_on) return # Fake turn on @@ -544,7 +544,7 @@ class ClimateEntity(Entity): async def async_turn_off(self) -> None: """Turn the entity off.""" if hasattr(self, "turn_off"): - await self.hass.async_add_executor_job(self.turn_off) # type: ignore[attr-defined] + await self.hass.async_add_executor_job(self.turn_off) return # Fake turn off diff --git a/homeassistant/components/knx/__init__.py b/homeassistant/components/knx/__init__.py index fa014335df9..2ca37cc39eb 100644 --- a/homeassistant/components/knx/__init__.py +++ b/homeassistant/components/knx/__init__.py @@ -500,7 +500,7 @@ class KNXModule: transcoder := DPTBase.parse_transcoder(dpt) ): self._address_filter_transcoder.update( - {_filter: transcoder for _filter in _filters} # type: ignore[misc] + {_filter: transcoder for _filter in _filters} # type: ignore[type-abstract] ) return self.xknx.telegram_queue.register_telegram_received_cb( @@ -532,7 +532,7 @@ class KNXModule: transcoder := DPTBase.parse_transcoder(dpt) ): self._group_address_transcoder.update( - {_address: transcoder for _address in group_addresses} # type: ignore[misc] + {_address: transcoder for _address in group_addresses} # type: ignore[type-abstract] ) for group_address in group_addresses: if group_address in self._knx_event_callback.group_addresses: diff --git a/homeassistant/components/knx/schema.py b/homeassistant/components/knx/schema.py index 13f6f153daf..3850119f387 100644 --- a/homeassistant/components/knx/schema.py +++ b/homeassistant/components/knx/schema.py @@ -79,8 +79,8 @@ def dpt_subclass_validator(dpt_base_class: type[DPTBase]) -> Callable[[Any], str return dpt_value_validator -numeric_type_validator = dpt_subclass_validator(DPTNumeric) # type: ignore[misc] -sensor_type_validator = dpt_subclass_validator(DPTBase) # type: ignore[misc] +numeric_type_validator = dpt_subclass_validator(DPTNumeric) # type: ignore[type-abstract] +sensor_type_validator = dpt_subclass_validator(DPTBase) # type: ignore[type-abstract] string_type_validator = dpt_subclass_validator(DPTString) diff --git a/homeassistant/components/media_player/__init__.py b/homeassistant/components/media_player/__init__.py index 5771e1b6938..c43c9980c19 100644 --- a/homeassistant/components/media_player/__init__.py +++ b/homeassistant/components/media_player/__init__.py @@ -920,9 +920,7 @@ class MediaPlayerEntity(Entity): async def async_toggle(self) -> None: """Toggle the power on the media player.""" if hasattr(self, "toggle"): - await self.hass.async_add_executor_job( - self.toggle # type: ignore[attr-defined] - ) + await self.hass.async_add_executor_job(self.toggle) return if self.state in { @@ -940,9 +938,7 @@ class MediaPlayerEntity(Entity): This method is a coroutine. """ if hasattr(self, "volume_up"): - await self.hass.async_add_executor_job( - self.volume_up # type: ignore[attr-defined] - ) + await self.hass.async_add_executor_job(self.volume_up) return if ( @@ -958,9 +954,7 @@ class MediaPlayerEntity(Entity): This method is a coroutine. """ if hasattr(self, "volume_down"): - await self.hass.async_add_executor_job( - self.volume_down # type: ignore[attr-defined] - ) + await self.hass.async_add_executor_job(self.volume_down) return if ( @@ -973,9 +967,7 @@ class MediaPlayerEntity(Entity): async def async_media_play_pause(self) -> None: """Play or pause the media player.""" if hasattr(self, "media_play_pause"): - await self.hass.async_add_executor_job( - self.media_play_pause # type: ignore[attr-defined] - ) + await self.hass.async_add_executor_job(self.media_play_pause) return if self.state == MediaPlayerState.PLAYING: diff --git a/homeassistant/components/notify/legacy.py b/homeassistant/components/notify/legacy.py index c3bb02896e0..0172fbc98d0 100644 --- a/homeassistant/components/notify/legacy.py +++ b/homeassistant/components/notify/legacy.py @@ -282,7 +282,7 @@ class BaseNotificationService: if hasattr(self, "targets"): stale_targets = set(self.registered_targets) - for name, target in self.targets.items(): # type: ignore[attr-defined] + for name, target in self.targets.items(): target_name = slugify(f"{self._target_service_name_prefix}_{name}") if target_name in stale_targets: stale_targets.remove(target_name) diff --git a/homeassistant/components/recorder/models.py b/homeassistant/components/recorder/models.py index cfc797cf7ea..3ab8b890838 100644 --- a/homeassistant/components/recorder/models.py +++ b/homeassistant/components/recorder/models.py @@ -160,7 +160,7 @@ class LazyState(State): """Set attributes.""" self._attributes = value - @property # type: ignore[override] + @property def context(self) -> Context: """State context.""" if self._context is None: @@ -172,7 +172,7 @@ class LazyState(State): """Set context.""" self._context = value - @property # type: ignore[override] + @property def last_changed(self) -> datetime: """Last changed datetime.""" if self._last_changed is None: @@ -187,7 +187,7 @@ class LazyState(State): """Set last changed datetime.""" self._last_changed = value - @property # type: ignore[override] + @property def last_updated(self) -> datetime: """Last updated datetime.""" if self._last_updated is None: diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 57cfe362231..d4f8128f643 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -705,9 +705,9 @@ class Entity(ABC): try: task: asyncio.Future[None] if hasattr(self, "async_update"): - task = self.hass.async_create_task(self.async_update()) # type: ignore[attr-defined] + task = self.hass.async_create_task(self.async_update()) elif hasattr(self, "update"): - task = self.hass.async_add_executor_job(self.update) # type: ignore[attr-defined] + task = self.hass.async_add_executor_job(self.update) else: return diff --git a/homeassistant/util/yaml/dumper.py b/homeassistant/util/yaml/dumper.py index 9f69c6c346e..db8b496d90e 100644 --- a/homeassistant/util/yaml/dumper.py +++ b/homeassistant/util/yaml/dumper.py @@ -12,7 +12,9 @@ from .objects import Input, NodeListClass try: from yaml import CSafeDumper as FastestAvailableSafeDumper except ImportError: - from yaml import SafeDumper as FastestAvailableSafeDumper # type: ignore[misc] + from yaml import ( # type: ignore[assignment] + SafeDumper as FastestAvailableSafeDumper, + ) def dump(_dict: dict) -> str: diff --git a/homeassistant/util/yaml/loader.py b/homeassistant/util/yaml/loader.py index 09e19af6840..62d754329c4 100644 --- a/homeassistant/util/yaml/loader.py +++ b/homeassistant/util/yaml/loader.py @@ -18,7 +18,7 @@ try: HAS_C_LOADER = True except ImportError: HAS_C_LOADER = False - from yaml import SafeLoader as FastestAvailableSafeLoader # type: ignore[misc] + from yaml import SafeLoader as FastestAvailableSafeLoader # type: ignore[assignment] from homeassistant.exceptions import HomeAssistantError diff --git a/mypy.ini b/mypy.ini index 3f0e917f167..988701393d6 100644 --- a/mypy.ini +++ b/mypy.ini @@ -14,6 +14,7 @@ warn_redundant_casts = true warn_unused_configs = true warn_unused_ignores = true enable_error_code = ignore-without-code +disable_error_code = annotation-unchecked strict_concatenate = false check_untyped_defs = true disallow_incomplete_defs = true diff --git a/requirements_test.txt b/requirements_test.txt index 06bd7e878ce..e0cbafbd6d4 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -12,7 +12,7 @@ codecov==2.1.12 coverage==6.4.4 freezegun==1.2.2 mock-open==1.4.0 -mypy==0.982 +mypy==0.990 pre-commit==2.20.0 pylint==2.15.5 pipdeptree==2.3.1 diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index 0c598df9cd1..99e07bcf118 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -46,7 +46,8 @@ GENERAL_SETTINGS: Final[dict[str, str]] = { "warn_redundant_casts": "true", "warn_unused_configs": "true", "warn_unused_ignores": "true", - "enable_error_code": "ignore-without-code", + "enable_error_code": ", ".join(["ignore-without-code"]), + "disable_error_code": ", ".join(["annotation-unchecked"]), # Strict_concatenate breaks passthrough ParamSpec typing "strict_concatenate": "false", }