Skip to content

Commit b1a70a9

Browse files
authored
Merge pull request #168 from robamu-org/typing-improvement-com-if
typing improvement for ComInterface
2 parents 6192ccf + a2e33fd commit b1a70a9

File tree

6 files changed

+22
-14
lines changed

6 files changed

+22
-14
lines changed

src/tmtccmd/com/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"""Communication module. Provides generic abstraction for communication and commonly used
33
concrete implementations."""
44

5-
from abc import abstractmethod, ABC
6-
from typing import Any, List, Optional
5+
from __future__ import annotations
76

8-
from tmtccmd.tmtc.common import TelemetryListT
7+
from abc import abstractmethod, ABC
8+
from typing import Any, Optional
99

1010

1111
class ReceptionDecodeError(Exception):
@@ -61,14 +61,14 @@ def close(self, args: Any = 0):
6161
"""
6262

6363
@abstractmethod
64-
def send(self, data: bytes):
64+
def send(self, data: bytes | bytearray):
6565
"""Send raw data.
6666
6767
:raises SendError: Sending failed for some reason.
6868
"""
6969

7070
@abstractmethod
71-
def receive(self, parameters: Any = 0) -> List[bytes]:
71+
def receive(self, parameters: Any = 0) -> list[bytes]:
7272
"""Returns a list of received packets. The child class can use a separate thread to poll for
7373
the packets or use some other mechanism and container like a deque to store packets
7474
to be returned here.

src/tmtccmd/com/dummy.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
external hardware or an extra socket
33
"""
44

5-
from typing import List, Optional
5+
from __future__ import annotations
6+
7+
from typing import Optional
68

79
from deprecated.sphinx import deprecated
810
from spacepackets.ccsds.time import CdsShortTimestamp
@@ -133,9 +135,9 @@ def data_available(self, timeout: float = 0, parameters: any = 0):
133135
return True
134136
return False
135137

136-
def receive(self, parameters: any = 0) -> List[bytes]:
138+
def receive(self, parameters: any = 0) -> list[bytes]:
137139
return self.dummy_handler.receive_reply_package()
138140

139-
def send(self, data: bytes):
141+
def send(self, data: bytes | bytearray):
140142
if data is not None:
141143
self.dummy_handler.insert_telecommand(data)

src/tmtccmd/com/serial_cobs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
import collections
23
import logging
34
import threading
@@ -49,7 +50,7 @@ def close(self, args: any = None) -> None:
4950
self.__reception_thread.join(0.4)
5051
super().close_port()
5152

52-
def send(self, data: bytes):
53+
def send(self, data: bytes | bytearray):
5354
encoded = bytearray([0])
5455
encoded.extend(cobs.encode(data))
5556
encoded.append(0)

src/tmtccmd/com/serial_dle.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
import dataclasses
23
import logging
34
import threading
@@ -87,7 +88,7 @@ def close(self, args: any = None) -> None:
8788
self.__reception_thread.join(0.4)
8889
super().close_port()
8990

90-
def send(self, data: bytes):
91+
def send(self, data: bytes | bytearray):
9192
encoded_data = self.__encoder.encode(source_packet=data, add_stx_etx=True)
9293
self.serial.write(encoded_data)
9394

src/tmtccmd/com/tcp.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""TCP communication interface"""
22

3+
from __future__ import annotations
4+
35
import logging
46
import queue
57
import socket
@@ -8,7 +10,7 @@
810
import threading
911
import select
1012
from collections import deque
11-
from typing import Any, List, Optional, Sequence
13+
from typing import Any, Optional, Sequence
1214

1315
from spacepackets.ccsds.spacepacket import parse_space_packets, PacketId
1416

@@ -123,10 +125,10 @@ def close(self, args: any = None) -> None:
123125
self.__connected = False
124126
self.__tcp_socket = None
125127

126-
def send(self, data: bytes):
128+
def send(self, data: bytes | bytearray):
127129
self.__tc_queue.put(data)
128130

129-
def receive(self, poll_timeout: float = 0) -> List[bytes]:
131+
def receive(self, poll_timeout: float = 0) -> list[bytes]:
130132
self.__tm_queue_to_packet_list()
131133
tm_packet_list = self.tm_packet_list
132134
self.tm_packet_list = []

src/tmtccmd/com/udp.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""UDP Communication Interface"""
22

3+
from __future__ import annotations
4+
35
import logging
46
import select
57
import socket
@@ -64,7 +66,7 @@ def close(self, args: any = None) -> None:
6466
if self.udp_socket is not None:
6567
self.udp_socket.close()
6668

67-
def send(self, data: bytes):
69+
def send(self, data: bytes | bytearray):
6870
if self.udp_socket is None:
6971
return
7072
bytes_sent = self.udp_socket.sendto(data, self.send_address.to_tuple)

0 commit comments

Comments
 (0)