Update mypy to 1.6.0 (#101780)

This commit is contained in:
Marc Mueller 2023-10-11 13:25:11 +02:00 committed by GitHub
parent f116e83b62
commit 0b2b486754
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 32 additions and 28 deletions

View File

@ -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

View File

@ -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]

View File

@ -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:

View File

@ -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]

View File

@ -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:

View File

@ -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."""

View File

@ -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(

View File

@ -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]:

View File

@ -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)

View File

@ -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."""

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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)):

View File

@ -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(

View File

@ -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

View File

@ -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

View File

@ -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",