Skip to content

Commit 76cc5f0

Browse files
committed
typing: modernize annotations
1 parent 7480d8e commit 76cc5f0

File tree

17 files changed

+60
-62
lines changed

17 files changed

+60
-62
lines changed

src/enapter/http/api/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from typing import MutableMapping, Optional
2+
from typing import MutableMapping
33

44

55
class Config:
@@ -16,7 +16,7 @@ def from_env(
1616
base_url=env.get(prefix + "BASE_URL"),
1717
)
1818

19-
def __init__(self, token: str, base_url: Optional[str] = None) -> None:
19+
def __init__(self, token: str, base_url: str | None = None) -> None:
2020
if not token:
2121
raise ValueError("token is missing")
2222
self.token = token

src/enapter/http/api/devices/communication_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import dataclasses
2-
from typing import Any, Dict
2+
from typing import Any
33

44
from .mqtt_credentials import MQTTCredentials
55
from .mqtt_protocol import MQTTProtocol
@@ -21,7 +21,7 @@ class CommunicationConfig:
2121
channel_id: str
2222

2323
@classmethod
24-
def from_dto(cls, dto: Dict[str, Any]) -> "CommunicationConfig":
24+
def from_dto(cls, dto: dict[str, Any]) -> "CommunicationConfig":
2525
mqtt_protocol = MQTTProtocol(dto["mqtt_protocol"])
2626
mqtt_credentials: MQTTCredentials | MQTTSCredentials | None = None
2727
match mqtt_protocol:

src/enapter/http/api/devices/device.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import dataclasses
22
import datetime
3-
from typing import Any, Dict
3+
from typing import Any
44

55
from .authorized_role import AuthorizedRole
66
from .device_type import DeviceType
@@ -19,7 +19,7 @@ class Device:
1919
authorized_role: AuthorizedRole
2020

2121
@classmethod
22-
def from_dto(cls, dto: Dict[str, Any]) -> "Device":
22+
def from_dto(cls, dto: dict[str, Any]) -> "Device":
2323
return cls(
2424
id=dto["id"],
2525
blueprint_id=dto["blueprint_id"],
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import dataclasses
2-
from typing import Any, Dict
2+
from typing import Any
33

44

55
@dataclasses.dataclass
@@ -9,5 +9,5 @@ class MQTTCredentials:
99
password: str
1010

1111
@classmethod
12-
def from_dto(cls, dto: Dict[str, Any]) -> "MQTTCredentials":
12+
def from_dto(cls, dto: dict[str, Any]) -> "MQTTCredentials":
1313
return cls(username=dto["username"], password=dto["password"])

src/enapter/http/api/devices/mqtts_credentials.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import dataclasses
2-
from typing import Any, Dict
2+
from typing import Any
33

44

55
@dataclasses.dataclass
@@ -10,7 +10,7 @@ class MQTTSCredentials:
1010
ca_chain: str
1111

1212
@classmethod
13-
def from_dto(cls, dto: Dict[str, Any]) -> "MQTTSCredentials":
13+
def from_dto(cls, dto: dict[str, Any]) -> "MQTTSCredentials":
1414
return cls(
1515
private_key=dto["private_key"],
1616
certificate=dto["certificate"],

src/enapter/log/json_formatter.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import datetime
22
import logging
3-
from typing import Any, Dict
3+
from typing import Any
44

55
import json_log_formatter # type: ignore
66

77

88
class JSONFormatter(json_log_formatter.JSONFormatter):
9+
910
def json_record(
10-
self,
11-
message: str,
12-
extra: Dict[str, Any],
13-
record: logging.LogRecord,
14-
) -> Dict[str, Any]:
11+
self, message: str, extra: dict[str, Any], record: logging.LogRecord
12+
) -> dict[str, Any]:
1513
try:
1614
del extra["taskName"]
1715
except KeyError:
@@ -34,5 +32,5 @@ def json_record(
3432

3533
return json_record
3634

37-
def mutate_json_record(self, json_record: Dict[str, Any]) -> Dict[str, Any]:
35+
def mutate_json_record(self, json_record: dict[str, Any]) -> dict[str, Any]:
3836
return json_record

src/enapter/mqtt/api/command_request.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import dataclasses
2-
from typing import Any, Dict
2+
from typing import Any
33

44
from .command_response import CommandResponse
55
from .command_state import CommandState
@@ -11,25 +11,25 @@ class CommandRequest(Message):
1111

1212
id: str
1313
name: str
14-
arguments: Dict[str, Any]
14+
arguments: dict[str, Any]
1515

1616
@classmethod
17-
def from_dto(cls, dto: Dict[str, Any]) -> "CommandRequest":
17+
def from_dto(cls, dto: dict[str, Any]) -> "CommandRequest":
1818
return cls(
1919
id=dto["id"],
2020
name=dto["name"],
2121
arguments=dto.get("arguments", {}),
2222
)
2323

24-
def to_dto(self) -> Dict[str, Any]:
24+
def to_dto(self) -> dict[str, Any]:
2525
return {
2626
"id": self.id,
2727
"name": self.name,
2828
"arguments": self.arguments,
2929
}
3030

3131
def new_response(
32-
self, state: CommandState, payload: Dict[str, Any]
32+
self, state: CommandState, payload: dict[str, Any]
3333
) -> CommandResponse:
3434
return CommandResponse(
3535
id=self.id,

src/enapter/mqtt/api/command_response.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import dataclasses
2-
from typing import Any, Dict
2+
from typing import Any
33

44
from .command_state import CommandState
55
from .message import Message
@@ -10,17 +10,17 @@ class CommandResponse(Message):
1010

1111
id: str
1212
state: CommandState
13-
payload: Dict[str, Any]
13+
payload: dict[str, Any]
1414

1515
@classmethod
16-
def from_dto(cls, dto: Dict[str, Any]) -> "CommandResponse":
16+
def from_dto(cls, dto: dict[str, Any]) -> "CommandResponse":
1717
return cls(
1818
id=dto["id"],
1919
state=CommandState(dto["state"]),
2020
payload=dto.get("payload", {}),
2121
)
2222

23-
def to_dto(self) -> Dict[str, Any]:
23+
def to_dto(self) -> dict[str, Any]:
2424
return {
2525
"id": self.id,
2626
"state": self.state.value,

src/enapter/mqtt/api/log.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import dataclasses
2-
from typing import Any, Dict
2+
from typing import Any
33

44
from .log_severity import LogSeverity
55
from .message import Message
@@ -14,15 +14,15 @@ class Log(Message):
1414
persist: bool
1515

1616
@classmethod
17-
def from_dto(cls, dto: Dict[str, Any]) -> "Log":
17+
def from_dto(cls, dto: dict[str, Any]) -> "Log":
1818
return cls(
1919
timestamp=dto["timestamp"],
2020
message=dto["message"],
2121
severity=LogSeverity(dto["severity"]),
2222
persist=dto["persist"],
2323
)
2424

25-
def to_dto(self) -> Dict[str, Any]:
25+
def to_dto(self) -> dict[str, Any]:
2626
return {
2727
"timestamp": self.timestamp,
2828
"message": self.message,

src/enapter/mqtt/api/message.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import abc
22
import json
3-
from typing import Any, Dict, Union
3+
from typing import Any
44

55

66
class Message(abc.ABC):
77

88
@classmethod
99
@abc.abstractmethod
10-
def from_dto(cls, dto: Dict[str, Any]):
10+
def from_dto(cls, dto: dict[str, Any]):
1111
pass
1212

1313
@abc.abstractmethod
14-
def to_dto(self) -> Dict[str, Any]:
14+
def to_dto(self) -> dict[str, Any]:
1515
pass
1616

1717
@classmethod
18-
def from_json(cls, data: Union[str, bytes]):
18+
def from_json(cls, data: str | bytes):
1919
dto = json.loads(data)
2020
return cls.from_dto(dto)
2121

0 commit comments

Comments
 (0)