Skip to content

Commit 9e49453

Browse files
committed
Switch to postponed annotation evaluation
1 parent 73d553b commit 9e49453

File tree

12 files changed

+124
-128
lines changed

12 files changed

+124
-128
lines changed

zigpy_znp/api.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import time
24
import typing
35
import asyncio
@@ -26,7 +28,7 @@
2628

2729
def _deduplicate_commands(
2830
commands: typing.Iterable[t.CommandBase],
29-
) -> typing.Tuple[t.CommandBase]:
31+
) -> tuple[t.CommandBase]:
3032
"""
3133
Deduplicates an iterable of commands by folding more-specific commands into less-
3234
specific commands. Used to avoid triggering callbacks multiple times per packet.
@@ -59,7 +61,7 @@ def _deduplicate_commands(
5961

6062
@dataclasses.dataclass(frozen=True)
6163
class BaseResponseListener:
62-
matching_commands: typing.Tuple[t.CommandBase]
64+
matching_commands: tuple[t.CommandBase]
6365

6466
def __post_init__(self):
6567
commands = _deduplicate_commands(self.matching_commands)
@@ -70,7 +72,7 @@ def __post_init__(self):
7072
# We're frozen so __setattr__ is disallowed
7173
object.__setattr__(self, "matching_commands", commands)
7274

73-
def matching_headers(self) -> typing.Set[t.CommandHeader]:
75+
def matching_headers(self) -> set[t.CommandHeader]:
7476
"""
7577
Returns the set of Z-Stack MT command headers for all the matching commands.
7678
"""

zigpy_znp/commands/zdo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
was received and executed. The result of the command execution will be conveyed to
77
the tester via a callback message interface"""
88

9-
import typing
9+
from __future__ import annotations
1010

1111
import zigpy.zdo.types
1212

@@ -127,7 +127,7 @@ class ChildInfoList(t.LVList, item_type=t.EUI64, length_type=t.uint8_t):
127127

128128
class NullableNodeDescriptor(zigpy.zdo.types.NodeDescriptor):
129129
@classmethod
130-
def deserialize(cls, data: bytes) -> typing.Tuple["NullableNodeDescriptor", bytes]:
130+
def deserialize(cls, data: bytes) -> tuple[NullableNodeDescriptor, bytes]:
131131
if data == b"\x00":
132132
return cls(), b""
133133

zigpy_znp/frames.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import typing
1+
from __future__ import annotations
2+
23
import functools
34
import dataclasses
45

@@ -57,7 +58,7 @@ class TransportFrame:
5758
payload: GeneralFrame
5859

5960
@classmethod
60-
def deserialize(cls, data: bytes) -> typing.Tuple["TransportFrame", bytes]:
61+
def deserialize(cls, data: bytes) -> tuple[TransportFrame, bytes]:
6162
sof, data = t.uint8_t.deserialize(data)
6263

6364
if sof != cls.SOF:

zigpy_znp/tools/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from __future__ import annotations
22

3-
import typing
43
import logging
54
import argparse
65

76
import jsonschema
87
import coloredlogs
98

9+
import zigpy_znp.types as t
1010
import zigpy_znp.logger as log
1111

1212
LOG_LEVELS = [logging.INFO, logging.DEBUG, log._TRACE]
@@ -106,7 +106,7 @@
106106
}
107107

108108

109-
def validate_backup_json(backup: dict[str, typing.Any]) -> None:
109+
def validate_backup_json(backup: t.JSONType) -> None:
110110
jsonschema.validate(backup, schema=OPEN_COORDINATOR_BACKUP_SCHEMA)
111111

112112

zigpy_znp/tools/flash_write.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from __future__ import annotations
2+
13
import sys
2-
import typing
34
import asyncio
45
import logging
56
import argparse
@@ -38,7 +39,7 @@ def compute_crc16(data: bytes) -> int:
3839
return crc
3940

4041

41-
def get_firmware_crcs(firmware: bytes) -> typing.Tuple[int, int]:
42+
def get_firmware_crcs(firmware: bytes) -> tuple[int, int]:
4243
# There is room for *two* CRCs in the firmware file: the expected and the computed
4344
firmware_without_crcs = (
4445
firmware[: c.ubl.IMAGE_CRC_OFFSET]

zigpy_znp/tools/network_backup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import sys
44
import json
5-
import typing
65
import asyncio
76
import logging
87
import argparse
@@ -19,7 +18,7 @@
1918
LOGGER = logging.getLogger(__name__)
2019

2120

22-
async def backup_network(radio_path: str) -> dict[str, typing.Any]:
21+
async def backup_network(radio_path: str) -> t.JSONType:
2322
znp = ZNP(ControllerApplication.SCHEMA({"device": {"path": radio_path}}))
2423
await znp.connect()
2524

zigpy_znp/tools/network_restore.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import sys
44
import json
5-
import typing
65
import asyncio
76
import argparse
87

@@ -16,7 +15,7 @@
1615

1716
async def restore_network(
1817
radio_path: str,
19-
backup: dict[str, typing.Any],
18+
backup: t.JSONType,
2019
counter_increment: int,
2120
) -> None:
2221
pan_id, _ = t.NWK.deserialize(bytes.fromhex(backup["pan_id"])[::-1])

zigpy_znp/types/basic.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
from __future__ import annotations
2+
13
import enum
2-
import typing
34

45
from zigpy_znp.types.cstruct import CStruct
56

67

78
class Bytes(bytes):
8-
def serialize(self) -> "Bytes":
9+
def serialize(self) -> Bytes:
910
return self
1011

1112
@classmethod
12-
def deserialize(cls, data: bytes) -> typing.Tuple["Bytes", bytes]:
13+
def deserialize(cls, data: bytes) -> tuple[Bytes, bytes]:
1314
return cls(data), b""
1415

1516
def __repr__(self) -> str:
@@ -76,7 +77,7 @@ def serialize(self) -> bytes:
7677
raise ValueError(str(e)) from e
7778

7879
@classmethod
79-
def deserialize(cls, data: bytes) -> typing.Tuple["FixedIntType", bytes]:
80+
def deserialize(cls, data: bytes) -> tuple[FixedIntType, bytes]:
8081
if len(data) < cls._size:
8182
raise ValueError(f"Data is too short to contain {cls._size} bytes")
8283

@@ -160,11 +161,11 @@ class uint64_t(uint_t, size=8):
160161
class ShortBytes(Bytes):
161162
_header = uint8_t
162163

163-
def serialize(self) -> "Bytes":
164+
def serialize(self) -> Bytes:
164165
return self._header(len(self)).serialize() + self
165166

166167
@classmethod
167-
def deserialize(cls, data: bytes) -> typing.Tuple[Bytes, bytes]:
168+
def deserialize(cls, data: bytes) -> tuple[Bytes, bytes]:
168169
length, data = cls._header.deserialize(data)
169170
if length > len(data):
170171
raise ValueError(f"Data is too short to contain {length} bytes of data")
@@ -211,7 +212,7 @@ def serialize(self, *, align=False) -> bytes:
211212
)
212213

213214
@classmethod
214-
def deserialize(cls, data: bytes, *, align=False) -> typing.Tuple["LVList", bytes]:
215+
def deserialize(cls, data: bytes, *, align=False) -> tuple[LVList, bytes]:
215216
length, data = cls._header.deserialize(data)
216217
r = cls()
217218
for i in range(length):
@@ -239,9 +240,7 @@ def serialize(self, *, align=False) -> bytes:
239240
return b"".join([self._serialize_item(i, align=align) for i in self])
240241

241242
@classmethod
242-
def deserialize(
243-
cls, data: bytes, *, align=False
244-
) -> typing.Tuple["FixedList", bytes]:
243+
def deserialize(cls, data: bytes, *, align=False) -> tuple[FixedList, bytes]:
245244
r = cls()
246245
for i in range(cls._length):
247246
item, data = cls._deserialize_item(data, align=align)
@@ -258,9 +257,7 @@ def serialize(self, *, align=False) -> bytes:
258257
return b"".join([self._serialize_item(i, align=align) for i in self])
259258

260259
@classmethod
261-
def deserialize(
262-
cls, data: bytes, *, align=False
263-
) -> typing.Tuple["CompleteList", bytes]:
260+
def deserialize(cls, data: bytes, *, align=False) -> tuple[CompleteList, bytes]:
264261
r = cls()
265262
while data:
266263
item, data = cls._deserialize_item(data, align=align)

zigpy_znp/types/commands.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from __future__ import annotations
2+
13
import enum
2-
import typing
34
import logging
45
import dataclasses
56

@@ -151,8 +152,8 @@ def __str__(self) -> str:
151152
class CommandDef:
152153
command_type: CommandType
153154
command_id: t.uint8_t
154-
req_schema: typing.Optional[tuple] = None
155-
rsp_schema: typing.Optional[tuple] = None
155+
req_schema: tuple | None = None
156+
rsp_schema: tuple | None = None
156157

157158

158159
class CommandsMeta(type):

0 commit comments

Comments
 (0)