diff --git a/homeassistant/auth/mfa_modules/__init__.py b/homeassistant/auth/mfa_modules/__init__.py index b89982127a0..aa28710d8c6 100644 --- a/homeassistant/auth/mfa_modules/__init__.py +++ b/homeassistant/auth/mfa_modules/__init__.py @@ -50,7 +50,7 @@ class MultiFactorAuthModule: Default is same as type """ - return self.config.get(CONF_ID, self.type) + return self.config.get(CONF_ID, self.type) # type: ignore[no-any-return] @property def type(self) -> str: @@ -60,7 +60,7 @@ class MultiFactorAuthModule: @property def name(self) -> str: """Return the name of the auth module.""" - return self.config.get(CONF_NAME, self.DEFAULT_TITLE) + return self.config.get(CONF_NAME, self.DEFAULT_TITLE) # type: ignore[no-any-return] # Implement by extending class diff --git a/homeassistant/auth/permissions/util.py b/homeassistant/auth/permissions/util.py index 7a1f102fdf3..402d43b7ab7 100644 --- a/homeassistant/auth/permissions/util.py +++ b/homeassistant/auth/permissions/util.py @@ -109,4 +109,4 @@ def test_all(policy: CategoryType, key: str) -> bool: if not isinstance(all_policy, dict): return bool(all_policy) - return all_policy.get(key, False) + return all_policy.get(key, False) # type: ignore[no-any-return] diff --git a/homeassistant/auth/providers/__init__.py b/homeassistant/auth/providers/__init__.py index 64d25a813ba..7d74dd2dc26 100644 --- a/homeassistant/auth/providers/__init__.py +++ b/homeassistant/auth/providers/__init__.py @@ -67,7 +67,7 @@ class AuthProvider: @property def name(self) -> str: """Return the name of the auth provider.""" - return self.config.get(CONF_NAME, self.DEFAULT_TITLE) + return self.config.get(CONF_NAME, self.DEFAULT_TITLE) # type: ignore[no-any-return] @property def support_mfa(self) -> bool: diff --git a/homeassistant/backports/functools.py b/homeassistant/backports/functools.py index d8b26e38449..6271bb87d14 100644 --- a/homeassistant/backports/functools.py +++ b/homeassistant/backports/functools.py @@ -78,4 +78,4 @@ class cached_property(Generic[_T]): raise TypeError(msg) from None return val - __class_getitem__ = classmethod(GenericAlias) + __class_getitem__ = classmethod(GenericAlias) # type: ignore[var-annotated] diff --git a/homeassistant/components/bond/utils.py b/homeassistant/components/bond/utils.py index 3a161a74bc5..ade8fd0b91d 100644 --- a/homeassistant/components/bond/utils.py +++ b/homeassistant/components/bond/utils.py @@ -70,7 +70,7 @@ class BondDevice: @property def trust_state(self) -> bool: """Check if Trust State is turned on.""" - return self.props.get("trust_state", False) + return self.props.get("trust_state", False) # type: ignore[no-any-return] def has_action(self, action: str) -> bool: """Check to see if the device supports an actions.""" @@ -203,7 +203,7 @@ class BondHub: @property def make(self) -> str: """Return this hub make.""" - return self._version.get("make", BRIDGE_MAKE) + return self._version.get("make", BRIDGE_MAKE) # type: ignore[no-any-return] @property def name(self) -> str: diff --git a/homeassistant/components/cloud/prefs.py b/homeassistant/components/cloud/prefs.py index 8b6f773e5d9..57179431574 100644 --- a/homeassistant/components/cloud/prefs.py +++ b/homeassistant/components/cloud/prefs.py @@ -197,7 +197,7 @@ class CloudPreferences: @property def alexa_report_state(self) -> bool: """Return if Alexa report state is enabled.""" - return self._prefs.get(PREF_ALEXA_REPORT_STATE, DEFAULT_ALEXA_REPORT_STATE) + return self._prefs.get(PREF_ALEXA_REPORT_STATE, DEFAULT_ALEXA_REPORT_STATE) # type: ignore[no-any-return] @property def alexa_default_expose(self) -> list[str] | None: @@ -210,7 +210,7 @@ class CloudPreferences: @property def alexa_entity_configs(self) -> dict[str, Any]: """Return Alexa Entity configurations.""" - return self._prefs.get(PREF_ALEXA_ENTITY_CONFIGS, {}) + return self._prefs.get(PREF_ALEXA_ENTITY_CONFIGS, {}) # type: ignore[no-any-return] @property def alexa_settings_version(self) -> int: @@ -227,7 +227,7 @@ class CloudPreferences: @property def google_report_state(self) -> bool: """Return if Google report state is enabled.""" - return self._prefs.get(PREF_GOOGLE_REPORT_STATE, DEFAULT_GOOGLE_REPORT_STATE) + return self._prefs.get(PREF_GOOGLE_REPORT_STATE, DEFAULT_GOOGLE_REPORT_STATE) # type: ignore[no-any-return] @property def google_secure_devices_pin(self) -> str | None: @@ -237,7 +237,7 @@ class CloudPreferences: @property def google_entity_configs(self) -> dict[str, dict[str, Any]]: """Return Google Entity configurations.""" - return self._prefs.get(PREF_GOOGLE_ENTITY_CONFIGS, {}) + return self._prefs.get(PREF_GOOGLE_ENTITY_CONFIGS, {}) # type: ignore[no-any-return] @property def google_settings_version(self) -> int: @@ -262,12 +262,12 @@ class CloudPreferences: @property def cloudhooks(self) -> dict[str, Any]: """Return the published cloud webhooks.""" - return self._prefs.get(PREF_CLOUDHOOKS, {}) + return self._prefs.get(PREF_CLOUDHOOKS, {}) # type: ignore[no-any-return] @property def tts_default_voice(self) -> tuple[str, str]: """Return the default TTS voice.""" - return self._prefs.get(PREF_TTS_DEFAULT_VOICE, DEFAULT_TTS_DEFAULT_VOICE) + return self._prefs.get(PREF_TTS_DEFAULT_VOICE, DEFAULT_TTS_DEFAULT_VOICE) # type: ignore[no-any-return] async def get_cloud_user(self) -> str: """Return ID of Home Assistant Cloud system user.""" diff --git a/homeassistant/components/doorbird/util.py b/homeassistant/components/doorbird/util.py index b3b62a4985a..c307a125b8d 100644 --- a/homeassistant/components/doorbird/util.py +++ b/homeassistant/components/doorbird/util.py @@ -11,7 +11,7 @@ from .models import DoorBirdData def get_mac_address_from_door_station_info(door_station_info: dict[str, Any]) -> str: """Get the mac address depending on the device type.""" - return door_station_info.get("PRIMARY_MAC_ADDR", door_station_info["WIFI_MAC_ADDR"]) + return door_station_info.get("PRIMARY_MAC_ADDR", door_station_info["WIFI_MAC_ADDR"]) # type: ignore[no-any-return] def get_door_station_by_token( diff --git a/homeassistant/components/emulated_hue/config.py b/homeassistant/components/emulated_hue/config.py index 379f0bec9d7..069fc3177d6 100644 --- a/homeassistant/components/emulated_hue/config.py +++ b/homeassistant/components/emulated_hue/config.py @@ -204,7 +204,7 @@ class Config: ): return self.entities[state.entity_id][CONF_ENTITY_NAME] - return state.attributes.get(ATTR_EMULATED_HUE_NAME, state.name) + return state.attributes.get(ATTR_EMULATED_HUE_NAME, state.name) # type: ignore[no-any-return] @cache # pylint: disable=method-cache-max-size-none def get_exposed_states(self) -> list[State]: diff --git a/homeassistant/components/isy994/sensor.py b/homeassistant/components/isy994/sensor.py index 1a160024a65..9e39f5d04e4 100644 --- a/homeassistant/components/isy994/sensor.py +++ b/homeassistant/components/isy994/sensor.py @@ -186,7 +186,7 @@ class ISYSensorEntity(ISYNodeEntity, SensorEntity): # Check if this is a known index pair UOM if isinstance(uom, dict): - return uom.get(value, value) + return uom.get(value, value) # type: ignore[no-any-return] if uom in (UOM_INDEX, UOM_ON_OFF): return cast(str, self.target.formatted) diff --git a/homeassistant/components/media_extractor/__init__.py b/homeassistant/components/media_extractor/__init__.py index 328871cf78c..39ce1f7a3bd 100644 --- a/homeassistant/components/media_extractor/__init__.py +++ b/homeassistant/components/media_extractor/__init__.py @@ -87,7 +87,7 @@ class MediaExtractor: def get_entities(self) -> list[str]: """Return list of entities.""" - return self.call_data.get(ATTR_ENTITY_ID, []) + return self.call_data.get(ATTR_ENTITY_ID, []) # type: ignore[no-any-return] def extract_and_send(self) -> None: """Extract exact stream format for each entity_id and play it.""" diff --git a/homeassistant/components/mysensors/climate.py b/homeassistant/components/mysensors/climate.py index e9d4502242e..d532135304a 100644 --- a/homeassistant/components/mysensors/climate.py +++ b/homeassistant/components/mysensors/climate.py @@ -144,7 +144,7 @@ class MySensorsHVAC(mysensors.device.MySensorsChildEntity, ClimateEntity): @property def hvac_mode(self) -> HVACMode: """Return current operation ie. heat, cool, idle.""" - return self._values.get(self.value_type, HVACMode.HEAT) + return self._values.get(self.value_type, HVACMode.HEAT) # type: ignore[no-any-return] @property def fan_mode(self) -> str | None: diff --git a/homeassistant/components/upcloud/__init__.py b/homeassistant/components/upcloud/__init__.py index 174d35f07e0..a2554858fef 100644 --- a/homeassistant/components/upcloud/__init__.py +++ b/homeassistant/components/upcloud/__init__.py @@ -211,7 +211,7 @@ class UpCloudServerEntity(CoordinatorEntity[UpCloudDataUpdateCoordinator]): def is_on(self) -> bool: """Return true if the server is on.""" try: - return STATE_MAP.get(self._server.state, self._server.state) == STATE_ON + return STATE_MAP.get(self._server.state, self._server.state) == STATE_ON # type: ignore[no-any-return] except AttributeError: return False diff --git a/homeassistant/data_entry_flow.py b/homeassistant/data_entry_flow.py index e22d4229511..545b799c467 100644 --- a/homeassistant/data_entry_flow.py +++ b/homeassistant/data_entry_flow.py @@ -468,12 +468,12 @@ class FlowHandler: @property def source(self) -> str | None: """Source that initialized the flow.""" - return self.context.get("source", None) + return self.context.get("source", None) # type: ignore[no-any-return] @property def show_advanced_options(self) -> bool: """If we should show advanced options.""" - return self.context.get("show_advanced_options", False) + return self.context.get("show_advanced_options", False) # type: ignore[no-any-return] def add_suggested_values_to_schema( self, data_schema: vol.Schema, suggested_values: Mapping[str, Any] | None diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index f0a05f7aded..4bb3e5ef5bd 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -161,7 +161,7 @@ def get_supported_features(hass: HomeAssistant, entity_id: str) -> int: First try the statemachine, then entity registry. """ if state := hass.states.get(entity_id): - return state.attributes.get(ATTR_SUPPORTED_FEATURES, 0) + return state.attributes.get(ATTR_SUPPORTED_FEATURES, 0) # type: ignore[no-any-return] entity_registry = er.async_get(hass) if not (entry := entity_registry.async_get(entity_id)): diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index b0754c13c7c..26b0674a351 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -2513,7 +2513,7 @@ class TemplateEnvironment(ImmutableSandboxedEnvironment): self.globals["expand"] = hassfunction(expand) self.filters["expand"] = self.globals["expand"] self.globals["closest"] = hassfunction(closest) - self.filters["closest"] = hassfunction(closest_filter) + self.filters["closest"] = hassfunction(closest_filter) # type: ignore[arg-type] self.globals["distance"] = hassfunction(distance) self.globals["is_hidden_entity"] = hassfunction(is_hidden_entity) self.tests["is_hidden_entity"] = hassfunction( diff --git a/mypy.ini b/mypy.ini index 94ad7cc018b..435a9f5f2ff 100644 --- a/mypy.ini +++ b/mypy.ini @@ -7,7 +7,6 @@ python_version = 3.11 plugins = pydantic.mypy show_error_codes = true follow_imports = silent -ignore_missing_imports = true local_partial_types = true strict_equality = true no_implicit_optional = true @@ -16,7 +15,7 @@ warn_redundant_casts = true warn_unused_configs = true warn_unused_ignores = true enable_error_code = ignore-without-code, redundant-self, truthy-iterable -disable_error_code = annotation-unchecked +disable_error_code = annotation-unchecked, import-not-found, import-untyped extra_checks = false check_untyped_defs = true disallow_incomplete_defs = true diff --git a/requirements_test.txt b/requirements_test.txt index d583ad5cc21..47d8fe1dcfe 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -11,7 +11,7 @@ astroid==3.0.0 coverage==7.3.2 freezegun==1.2.2 mock-open==1.4.0 -mypy==1.5.1 +mypy==1.6.0 pre-commit==3.4.0 pydantic==1.10.12 pylint==3.0.1 diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index 779d76078d6..5513105fa17 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -35,7 +35,6 @@ GENERAL_SETTINGS: Final[dict[str, str]] = { "show_error_codes": "true", "follow_imports": "silent", # Enable some checks globally. - "ignore_missing_imports": "true", "local_partial_types": "true", "strict_equality": "true", "no_implicit_optional": "true", @@ -50,7 +49,13 @@ GENERAL_SETTINGS: Final[dict[str, str]] = { "truthy-iterable", ] ), - "disable_error_code": ", ".join(["annotation-unchecked"]), + "disable_error_code": ", ".join( + [ + "annotation-unchecked", + "import-not-found", + "import-untyped", + ] + ), # Impractical in real code # E.g. this breaks passthrough ParamSpec typing with Concatenate "extra_checks": "false",