Skip to content

Commit

Permalink
Update mypy to 1.6.0 (home-assistant#101780)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored Oct 11, 2023
1 parent f116e83 commit 0b2b486
Show file tree
Hide file tree
Showing 18 changed files with 32 additions and 28 deletions.
4 changes: 2 additions & 2 deletions homeassistant/auth/mfa_modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def id(self) -> str:
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:
Expand All @@ -60,7 +60,7 @@ def type(self) -> str:
@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

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/auth/permissions/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
2 changes: 1 addition & 1 deletion homeassistant/auth/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def type(self) -> str:
@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:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/backports/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ def __get__(
raise TypeError(msg) from None
return val

__class_getitem__ = classmethod(GenericAlias)
__class_getitem__ = classmethod(GenericAlias) # type: ignore[var-annotated]
4 changes: 2 additions & 2 deletions homeassistant/components/bond/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def branding_profile(self) -> str | None:
@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."""
Expand Down Expand Up @@ -203,7 +203,7 @@ def model(self) -> str | None:
@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:
Expand Down
12 changes: 6 additions & 6 deletions homeassistant/components/cloud/prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def alexa_enabled(self) -> bool:
@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:
Expand All @@ -210,7 +210,7 @@ def alexa_default_expose(self) -> list[str] | None:
@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:
Expand All @@ -227,7 +227,7 @@ def google_enabled(self) -> bool:
@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:
Expand All @@ -237,7 +237,7 @@ def google_secure_devices_pin(self) -> str | None:
@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:
Expand All @@ -262,12 +262,12 @@ def google_default_expose(self) -> list[str] | None:
@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."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/doorbird/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

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(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/emulated_hue/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def get_entity_name(self, state: State) -> str:
):
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]:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/isy994/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def native_value(self) -> float | int | str | None:

# 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)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/media_extractor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def get_media_url(self) -> str:

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."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/mysensors/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def target_temperature_low(self) -> float | None:
@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:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/upcloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def icon(self) -> str:
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

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/data_entry_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/helpers/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/helpers/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -2513,7 +2513,7 @@ def warn_unsupported(*args: Any, **kwargs: Any) -> NoReturn:
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(
Expand Down
3 changes: 1 addition & 2 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions script/hassfest/mypy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"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",
Expand All @@ -50,7 +49,13 @@
"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",
Expand Down

0 comments on commit 0b2b486

Please sign in to comment.