Skip to content

Commit

Permalink
Update mypy to 1.1.1 (#89268)
Browse files Browse the repository at this point in the history
* Update mypy to 1.1.1
* Update pydantic to 1.10.6
  • Loading branch information
cdce8p committed Mar 8, 2023
1 parent bfae899 commit 386533a
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion homeassistant/block_async_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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
)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ async def start(self) -> None:
# 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()
Expand Down
8 changes: 6 additions & 2 deletions homeassistant/components/matter/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,11 +13,14 @@
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")
Expand Down
9 changes: 7 additions & 2 deletions homeassistant/components/p1_monitor/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,6 +18,9 @@
SERVICE_WATERMETER,
)

if TYPE_CHECKING:
from _typeshed import DataclassInstance

TO_REDACT = {
CONF_HOST,
}
Expand All @@ -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
2 changes: 1 addition & 1 deletion homeassistant/components/zeroconf/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ def new_zeroconf_init(self: zeroconf.Zeroconf, *k: Any, **kw: Any) -> 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]
7 changes: 5 additions & 2 deletions homeassistant/components/zwave_js/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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 (
Expand Down Expand Up @@ -60,6 +60,9 @@
)
from .helpers import ZwaveValueID

if TYPE_CHECKING:
from _typeshed import DataclassInstance


class ValueType(StrEnum):
"""Enum with all value types."""
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/helpers/aiohttp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/helpers/httpx_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/helpers/schema_config_entry_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def _async_get_options_flow(
)

# 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:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def new_event_loop(self) -> asyncio.AbstractEventLoop:
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
Expand Down
4 changes: 2 additions & 2 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 386533a

Please sign in to comment.