Skip to content

Commit 0907e5a

Browse files
committed
Fix type aliasing
1 parent b80386d commit 0907e5a

9 files changed

Lines changed: 22 additions & 10 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ repos:
55
additional_dependencies:
66
- types-requests
77
- types-simplejson
8-
rev: "v0.931"
8+
rev: "v1.17.1"
99
- repo: https://github.com/pre-commit/pre-commit-hooks
1010
hooks:
1111
- id: trailing-whitespace

docs/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
# The full version, including alpha/beta/rc tags
2828
with open("../pyproject.toml") as f:
2929
pyproject = f.read()
30-
release = version = re.search('version = "(.+?)"', pyproject).group(1)
30+
search_result = re.search('version = "(.+?)"', pyproject)
31+
assert search_result is not None
32+
release = version = search_result.group(1)
3133

3234
# -- General configuration ---------------------------------------------------
3335

homeassistant_api/models/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
from pydantic import BaseModel as PydanticBaseModel
77
from pydantic import ConfigDict, PlainSerializer
88

9+
__all__ = (
10+
"BaseModel",
11+
"DatetimeIsoField",
12+
)
13+
914
DatetimeIsoField = Annotated[
1015
datetime,
1116
PlainSerializer(lambda x: x.isoformat(), return_type=str, when_used="json"),

homeassistant_api/models/states.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
from homeassistant_api.models.base import BaseModel, DatetimeIsoField
1111

12+
__all__ = (
13+
"Context",
14+
"State",
15+
)
16+
1217

1318
class Context(BaseModel):
1419
"""Model for entity state contexts."""

homeassistant_api/models/websocket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from homeassistant_api.utils import JSONType
66

7-
from .base import BaseModel
8-
from .states import Context, DatetimeIsoField
7+
from .base import BaseModel, DatetimeIsoField
8+
from .states import Context
99

1010
__all__ = (
1111
"AuthRequired",

homeassistant_api/processing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def process_content(self, *, async_: bool = False) -> Any:
6161
calls the processor with the response.
6262
"""
6363

64-
mimetype_header = self._response.headers.get( # type: ignore [arg-type]
64+
mimetype_header = self._response.headers.get(
6565
"content-type",
6666
"text/plain",
6767
)

homeassistant_api/rawclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(
7373
if cache_session is False:
7474
self.cache_session = requests.Session()
7575
elif cache_session is None:
76-
self.cache_session = requests_cache.CachedSession( # type: ignore[attr-defined]
76+
self.cache_session = requests_cache.CachedSession(
7777
cache_name="default_cache",
7878
backend="memory",
7979
expire_after=300,

homeassistant_api/rawwebsocket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _recv(self) -> dict[str, JSONType]:
8484
raise ReceivingError("Connection is not open!")
8585
_bytes = self._conn.recv()
8686
logger.debug("Received message: %s", _bytes)
87-
return json.loads(_bytes)
87+
return cast(dict[str, JSONType], json.loads(_bytes))
8888

8989
def send(self, type: str, include_id: bool = True, **data: Any) -> int:
9090
"""
@@ -95,7 +95,7 @@ def send(self, type: str, include_id: bool = True, **data: Any) -> int:
9595
if include_id: # auth messages don't have an id
9696
data["id"] = self._request_id()
9797
data["type"] = type
98-
98+
assert isinstance(data["id"], int)
9999
self._send(data)
100100

101101
if "id" in data:

homeassistant_api/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
2-
from typing import Optional
2+
from typing import Optional, TypeAlias, Union
33

4-
JSONType = int | float | str | bool | list["JSONType"] | dict[str, "JSONType"]
4+
JSONType: TypeAlias = Union[int, float, str, bool, list["JSONType"], dict[str, "JSONType"]]
55

66

77
def format_entity_id(entity_id: str) -> str:

0 commit comments

Comments
 (0)