From 4fbb14ecc7135bf7c2adf6f71d3ffdcc79013e1a Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 7 Feb 2023 02:31:14 +0100 Subject: [PATCH] Update mypy to 1.0.0 (#87586) --- homeassistant/components/gios/__init__.py | 2 +- homeassistant/components/harmony/subscriber.py | 6 +++--- homeassistant/components/mqtt/client.py | 8 ++++---- homeassistant/components/samsungtv/bridge.py | 6 +++--- homeassistant/components/zha/core/gateway.py | 2 +- pyproject.toml | 4 ---- requirements_test.txt | 2 +- 7 files changed, 13 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/gios/__init__.py b/homeassistant/components/gios/__init__.py index adef70e5864..1ade1a83cc7 100644 --- a/homeassistant/components/gios/__init__.py +++ b/homeassistant/components/gios/__init__.py @@ -30,7 +30,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: _LOGGER.debug("Using station_id: %d", station_id) # We used to use int as config_entry unique_id, convert this to str. - if isinstance(entry.unique_id, int): # type: ignore[unreachable] + if isinstance(entry.unique_id, int): hass.config_entries.async_update_entry(entry, unique_id=str(station_id)) # type: ignore[unreachable] # We used to use int in device_entry identifiers, convert this to str. diff --git a/homeassistant/components/harmony/subscriber.py b/homeassistant/components/harmony/subscriber.py index 0c22d4b38b9..4804253151f 100644 --- a/homeassistant/components/harmony/subscriber.py +++ b/homeassistant/components/harmony/subscriber.py @@ -4,14 +4,14 @@ from __future__ import annotations import asyncio from collections.abc import Callable import logging -from typing import Any, NamedTuple, Optional +from typing import Any, NamedTuple from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback _LOGGER = logging.getLogger(__name__) -NoParamCallback = Optional[Callable[[], Any]] -ActivityCallback = Optional[Callable[[tuple], Any]] +NoParamCallback = Callable[[], Any] | None +ActivityCallback = Callable[[tuple], Any] | None class HarmonyCallback(NamedTuple): diff --git a/homeassistant/components/mqtt/client.py b/homeassistant/components/mqtt/client.py index 28d60a5fdb9..2563c507c16 100644 --- a/homeassistant/components/mqtt/client.py +++ b/homeassistant/components/mqtt/client.py @@ -10,7 +10,7 @@ import logging from operator import attrgetter import ssl import time -from typing import TYPE_CHECKING, Any, Union, cast +from typing import TYPE_CHECKING, Any, cast import uuid import attr @@ -151,9 +151,9 @@ AsyncDeprecatedMessageCallbackType = Callable[ [str, ReceivePayloadType, int], Coroutine[Any, Any, None] ] DeprecatedMessageCallbackType = Callable[[str, ReceivePayloadType, int], None] -DeprecatedMessageCallbackTypes = Union[ - AsyncDeprecatedMessageCallbackType, DeprecatedMessageCallbackType -] +DeprecatedMessageCallbackTypes = ( + AsyncDeprecatedMessageCallbackType | DeprecatedMessageCallbackType +) # Support for a deprecated callback type will be removed from HA core 2023.2.0 diff --git a/homeassistant/components/samsungtv/bridge.py b/homeassistant/components/samsungtv/bridge.py index 717ee1120f0..a2558367995 100644 --- a/homeassistant/components/samsungtv/bridge.py +++ b/homeassistant/components/samsungtv/bridge.py @@ -388,7 +388,7 @@ class SamsungTVWSBaseBridge(SamsungTVBridge, Generic[_RemoteT, _CommandT]): """Tells if the TV is on.""" LOGGER.debug("Checking if TV %s is on using websocket", self.host) if remote := await self._async_get_remote(): - return remote.is_alive() # type: ignore[no-any-return] + return remote.is_alive() return False async def _async_send_commands(self, commands: list[_CommandT]) -> None: @@ -399,7 +399,7 @@ class SamsungTVWSBaseBridge(SamsungTVBridge, Generic[_RemoteT, _CommandT]): for _ in range(retry_count + 1): try: if remote := await self._async_get_remote(): - await remote.send_commands(commands) + await remote.send_commands(commands) # type: ignore[arg-type] break except ( BrokenPipeError, @@ -416,7 +416,7 @@ class SamsungTVWSBaseBridge(SamsungTVBridge, Generic[_RemoteT, _CommandT]): """Create or return a remote control instance.""" if (remote := self._remote) and remote.is_alive(): # If we have one then try to use it - return remote # type: ignore[no-any-return] + return remote async with self._remote_lock: # If we don't have one make sure we do it under the lock diff --git a/homeassistant/components/zha/core/gateway.py b/homeassistant/components/zha/core/gateway.py index c87addd6713..a1691c1a419 100644 --- a/homeassistant/components/zha/core/gateway.py +++ b/homeassistant/components/zha/core/gateway.py @@ -91,7 +91,7 @@ if TYPE_CHECKING: from ..entity import ZhaEntity from .channels.base import ZigbeeChannel - _LogFilterType = Filter | Callable[[LogRecord], int] + _LogFilterType = Filter | Callable[[LogRecord], bool] _LOGGER = logging.getLogger(__name__) diff --git a/pyproject.toml b/pyproject.toml index 10fcb128af6..54f7c191a46 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -163,9 +163,6 @@ good-names = [ # Pylint CodeStyle plugin # consider-using-namedtuple-or-dataclass - too opinionated # consider-using-assignment-expr - decision to use := better left to devs -# --- -# Temporary for the Python 3.10 update, remove with mypy v1.0 -# consider-alternative-union-syntax disable = [ "format", "abstract-method", @@ -190,7 +187,6 @@ disable = [ "consider-using-f-string", "consider-using-namedtuple-or-dataclass", "consider-using-assignment-expr", - "consider-alternative-union-syntax", ] enable = [ #"useless-suppression", # temporarily every now and then to clean them up diff --git a/requirements_test.txt b/requirements_test.txt index 6c3933fbf62..a6b63c0fed0 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -12,7 +12,7 @@ codecov==2.1.12 coverage==7.1.0 freezegun==1.2.2 mock-open==1.4.0 -mypy==0.991 +mypy==1.0.0 pre-commit==3.0.0 pylint==2.16.0 pylint-per-file-ignores==1.1.0