From 97af16485883ea793e9fe11dce636888449f2dc6 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 26 Apr 2022 16:41:52 +0200 Subject: [PATCH] Prepare for upcoming mypy update (#70800) --- homeassistant/components/fritz/config_flow.py | 2 +- homeassistant/components/statistics/sensor.py | 4 ++-- homeassistant/helpers/frame.py | 2 +- homeassistant/helpers/network.py | 3 ++- homeassistant/util/async_.py | 4 ++-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/fritz/config_flow.py b/homeassistant/components/fritz/config_flow.py index ceec876e670..3e6961f585d 100644 --- a/homeassistant/components/fritz/config_flow.py +++ b/homeassistant/components/fritz/config_flow.py @@ -130,7 +130,7 @@ class FritzBoxToolsFlowHandler(ConfigFlow, domain=DOMAIN): ) self.context[CONF_HOST] = self._host - if ipaddress.ip_address(self._host).is_link_local: + if not self._host or ipaddress.ip_address(self._host).is_link_local: return self.async_abort(reason="ignore_ip6_link_local") if uuid := discovery_info.upnp.get(ssdp.ATTR_UPNP_UDN): diff --git a/homeassistant/components/statistics/sensor.py b/homeassistant/components/statistics/sensor.py index 99d166b8940..67ad10dd865 100644 --- a/homeassistant/components/statistics/sensor.py +++ b/homeassistant/components/statistics/sensor.py @@ -236,7 +236,7 @@ class StatisticsSensor(SensorEntity): samples_max_age: timedelta | None, precision: int, quantile_intervals: int, - quantile_method: str, + quantile_method: Literal["exclusive", "inclusive"], ) -> None: """Initialize the Statistics sensor.""" self._attr_icon: str = ICON @@ -252,7 +252,7 @@ class StatisticsSensor(SensorEntity): self._samples_max_age: timedelta | None = samples_max_age self._precision: int = precision self._quantile_intervals: int = quantile_intervals - self._quantile_method: str = quantile_method + self._quantile_method: Literal["exclusive", "inclusive"] = quantile_method self._value: StateType | datetime = None self._unit_of_measurement: str | None = None self._available: bool = False diff --git a/homeassistant/helpers/frame.py b/homeassistant/helpers/frame.py index 2baf7cdd713..b81f5f29432 100644 --- a/homeassistant/helpers/frame.py +++ b/homeassistant/helpers/frame.py @@ -109,7 +109,7 @@ def report_integration( integration, found_frame.filename[index:], found_frame.lineno, - found_frame.line.strip(), + (found_frame.line or "?").strip(), ) diff --git a/homeassistant/helpers/network.py b/homeassistant/helpers/network.py index 5fa10fd6fe8..a6060226d7b 100644 --- a/homeassistant/helpers/network.py +++ b/homeassistant/helpers/network.py @@ -236,7 +236,8 @@ def _get_internal_url( scheme="http", host=hass.config.api.local_ip, port=hass.config.api.port ) if ( - not is_loopback(ip_address(ip_url.host)) + ip_url.host + and not is_loopback(ip_address(ip_url.host)) and (not require_current_request or ip_url.host == _get_request_host()) and (not require_standard_port or ip_url.is_default_port()) ): diff --git a/homeassistant/util/async_.py b/homeassistant/util/async_.py index b27ddbda382..4e7d05f7c2e 100644 --- a/homeassistant/util/async_.py +++ b/homeassistant/util/async_.py @@ -155,13 +155,13 @@ def check_loop(func: Callable[..., Any], strict: bool = True) -> None: integration, found_frame.filename[index:], found_frame.lineno, - found_frame.line.strip(), + (found_frame.line or "?").strip(), ) if strict: raise RuntimeError( "Blocking calls must be done in the executor or a separate thread; " "Use `await hass.async_add_executor_job()` " - f"at {found_frame.filename[index:]}, line {found_frame.lineno}: {found_frame.line.strip()}" + f"at {found_frame.filename[index:]}, line {found_frame.lineno}: {(found_frame.line or '?').strip()}" )