diff --git a/homeassistant/block_async_io.py b/homeassistant/block_async_io.py index 753fda5ae9b..d7c1a7c9eea 100644 --- a/homeassistant/block_async_io.py +++ b/homeassistant/block_async_io.py @@ -8,7 +8,7 @@ from .util.async_ import protect_loop def enable() -> None: """Enable the detection of blocking calls in the event loop.""" # Prevent urllib3 and requests doing I/O in event loop - HTTPConnection.putrequest = protect_loop( # type: ignore[assignment] + HTTPConnection.putrequest = protect_loop( # type: ignore[method-assign] HTTPConnection.putrequest ) diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py index 1c201725c00..04b94dc3b81 100644 --- a/homeassistant/components/http/__init__.py +++ b/homeassistant/components/http/__init__.py @@ -460,7 +460,7 @@ class HomeAssistantHTTP: # This will now raise a RunTimeError. # To work around this we now prevent the router from getting frozen # pylint: disable-next=protected-access - self.app._router.freeze = lambda: None # type: ignore[assignment] + self.app._router.freeze = lambda: None # type: ignore[method-assign] self.runner = web.AppRunner(self.app) await self.runner.setup() diff --git a/homeassistant/components/matter/models.py b/homeassistant/components/matter/models.py index 3ce5f184672..2575b16e8b1 100644 --- a/homeassistant/components/matter/models.py +++ b/homeassistant/components/matter/models.py @@ -1,8 +1,9 @@ """Models used for the Matter integration.""" +from __future__ import annotations from collections.abc import Callable from dataclasses import asdict, dataclass -from typing import Any +from typing import TYPE_CHECKING, Any from chip.clusters import Objects as clusters from chip.clusters.Objects import ClusterAttributeDescriptor @@ -12,11 +13,14 @@ from matter_server.client.models.node import MatterEndpoint from homeassistant.const import Platform from homeassistant.helpers.entity import EntityDescription +if TYPE_CHECKING: + from _typeshed import DataclassInstance + class DataclassMustHaveAtLeastOne: """A dataclass that must have at least one input parameter that is not None.""" - def __post_init__(self) -> None: + def __post_init__(self: DataclassInstance) -> None: """Post dataclass initialization.""" if all(val is None for val in asdict(self).values()): raise ValueError("At least one input parameter must not be None") diff --git a/homeassistant/components/p1_monitor/diagnostics.py b/homeassistant/components/p1_monitor/diagnostics.py index 29f48d47cd9..b2668f060a4 100644 --- a/homeassistant/components/p1_monitor/diagnostics.py +++ b/homeassistant/components/p1_monitor/diagnostics.py @@ -2,7 +2,7 @@ from __future__ import annotations from dataclasses import asdict -from typing import Any +from typing import TYPE_CHECKING, Any, cast from homeassistant.components.diagnostics import async_redact_data from homeassistant.config_entries import ConfigEntry @@ -18,6 +18,9 @@ from .const import ( SERVICE_WATERMETER, ) +if TYPE_CHECKING: + from _typeshed import DataclassInstance + TO_REDACT = { CONF_HOST, } @@ -42,6 +45,8 @@ async def async_get_config_entry_diagnostics( } if coordinator.has_water_meter: - data["data"]["watermeter"] = asdict(coordinator.data[SERVICE_WATERMETER]) + data["data"]["watermeter"] = asdict( + cast("DataclassInstance", coordinator.data[SERVICE_WATERMETER]) + ) return data diff --git a/homeassistant/components/zeroconf/usage.py b/homeassistant/components/zeroconf/usage.py index 0c452149bfd..b9d51cd3c36 100644 --- a/homeassistant/components/zeroconf/usage.py +++ b/homeassistant/components/zeroconf/usage.py @@ -31,4 +31,4 @@ def install_multiple_zeroconf_catcher(hass_zc: HaZeroconf) -> None: return zeroconf.Zeroconf.__new__ = new_zeroconf_new # type: ignore[assignment] - zeroconf.Zeroconf.__init__ = new_zeroconf_init # type: ignore[assignment] + zeroconf.Zeroconf.__init__ = new_zeroconf_init # type: ignore[method-assign] diff --git a/homeassistant/components/zwave_js/discovery.py b/homeassistant/components/zwave_js/discovery.py index 5dfab3077e4..36295a64558 100644 --- a/homeassistant/components/zwave_js/discovery.py +++ b/homeassistant/components/zwave_js/discovery.py @@ -3,7 +3,7 @@ from __future__ import annotations from collections.abc import Generator from dataclasses import asdict, dataclass, field -from typing import Any +from typing import TYPE_CHECKING, Any from awesomeversion import AwesomeVersion from zwave_js_server.const import ( @@ -60,6 +60,9 @@ from .discovery_data_template import ( ) from .helpers import ZwaveValueID +if TYPE_CHECKING: + from _typeshed import DataclassInstance + class ValueType(StrEnum): """Enum with all value types.""" @@ -73,7 +76,7 @@ class ValueType(StrEnum): class DataclassMustHaveAtLeastOne: """A dataclass that must have at least one input parameter that is not None.""" - def __post_init__(self) -> None: + def __post_init__(self: DataclassInstance) -> None: """Post dataclass initialization.""" if all(val is None for val in asdict(self).values()): raise ValueError("At least one input parameter must not be None") diff --git a/homeassistant/helpers/aiohttp_client.py b/homeassistant/helpers/aiohttp_client.py index d623de5e816..f75b8e3aa40 100644 --- a/homeassistant/helpers/aiohttp_client.py +++ b/homeassistant/helpers/aiohttp_client.py @@ -129,7 +129,7 @@ def _async_create_clientsession( {USER_AGENT: SERVER_SOFTWARE}, ) - clientsession.close = warn_use( # type: ignore[assignment] + clientsession.close = warn_use( # type: ignore[method-assign] clientsession.close, WARN_CLOSE_MSG, ) diff --git a/homeassistant/helpers/httpx_client.py b/homeassistant/helpers/httpx_client.py index e02759b09f8..2475469a7d1 100644 --- a/homeassistant/helpers/httpx_client.py +++ b/homeassistant/helpers/httpx_client.py @@ -72,7 +72,7 @@ def create_async_httpx_client( original_aclose = client.aclose - client.aclose = warn_use( # type: ignore[assignment] + client.aclose = warn_use( # type: ignore[method-assign] client.aclose, "closes the Home Assistant httpx client" ) diff --git a/homeassistant/helpers/schema_config_entry_flow.py b/homeassistant/helpers/schema_config_entry_flow.py index 9f76a639e0f..5101e5c69a7 100644 --- a/homeassistant/helpers/schema_config_entry_flow.py +++ b/homeassistant/helpers/schema_config_entry_flow.py @@ -275,7 +275,7 @@ class SchemaConfigFlowHandler(config_entries.ConfigFlow, ABC): ) # Create an async_get_options_flow method - cls.async_get_options_flow = _async_get_options_flow # type: ignore[assignment] + cls.async_get_options_flow = _async_get_options_flow # type: ignore[method-assign] # Create flow step methods for each step defined in the flow schema for step in cls.config_flow: diff --git a/homeassistant/runner.py b/homeassistant/runner.py index 0926fb67459..e5a87a4b092 100644 --- a/homeassistant/runner.py +++ b/homeassistant/runner.py @@ -110,7 +110,7 @@ class HassEventLoopPolicy(asyncio.DefaultEventLoopPolicy): thread_name_prefix="SyncWorker", max_workers=MAX_EXECUTOR_WORKERS ) loop.set_default_executor(executor) - loop.set_default_executor = warn_use( # type: ignore[assignment] + loop.set_default_executor = warn_use( # type: ignore[method-assign] loop.set_default_executor, "sets default executor on the event loop" ) return loop diff --git a/requirements_test.txt b/requirements_test.txt index f5be4d07597..10ceb81365d 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -12,9 +12,9 @@ codecov==2.1.12 coverage==7.2.1 freezegun==1.2.2 mock-open==1.4.0 -mypy==1.0.1 +mypy==1.1.1 pre-commit==3.1.0 -pydantic==1.10.5 +pydantic==1.10.6 pylint==2.17.0 pylint-per-file-ignores==1.1.0 pipdeptree==2.5.0