Skip to content

Commit 3171d37

Browse files
Adding type annotations to gyro and location packet
1 parent 24695d3 commit 3171d37

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

adafruit_bluefruit_connect/gyro_packet.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
1313
"""
1414

15+
from __future__ import annotations
16+
1517
from ._xyz_packet import _XYZPacket
1618

1719

1820
class GyroPacket(_XYZPacket):
1921
"""A packet of x, y, z float values from a gyroscope."""
2022

2123
# Everything else is handled by _XYZPacket.
22-
_TYPE_HEADER = b"!G"
24+
_TYPE_HEADER: bytes = b"!G"
2325

2426

2527
# Register this class with the superclass. This allows the user to import only what is needed.

adafruit_bluefruit_connect/location_packet.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
1313
"""
1414

15+
from __future__ import annotations
16+
1517
import struct
1618

1719
from .packet import Packet
@@ -20,19 +22,19 @@
2022
class LocationPacket(Packet):
2123
"""A packet of latitude, longitude, and altitude values."""
2224

23-
_FMT_PARSE = "<xxfffx"
24-
PACKET_LENGTH = struct.calcsize(_FMT_PARSE)
25+
_FMT_PARSE: str = "<xxfffx"
26+
PACKET_LENGTH: int = struct.calcsize(_FMT_PARSE)
2527
# _FMT_CONSTRUCT doesn't include the trailing checksum byte.
26-
_FMT_CONSTRUCT = "<2sfff"
27-
_TYPE_HEADER = b"!L"
28+
_FMT_CONSTRUCT: str = "<2sfff"
29+
_TYPE_HEADER: bytes = b"!L"
2830

29-
def __init__(self, latitude, longitude, altitude):
31+
def __init__(self, latitude: float, longitude: float, altitude: float) -> None:
3032
"""Construct a LocationPacket from the given values."""
3133
self._latitude = latitude
3234
self._longitude = longitude
3335
self._altitude = altitude
3436

35-
def to_bytes(self):
37+
def to_bytes(self) -> bytes:
3638
"""Return the bytes needed to send this packet."""
3739
partial_packet = struct.pack(
3840
self._FMT_CONSTRUCT,
@@ -44,17 +46,17 @@ def to_bytes(self):
4446
return self.add_checksum(partial_packet)
4547

4648
@property
47-
def latitude(self):
49+
def latitude(self) -> float:
4850
"""The latitude value."""
4951
return self._latitude
5052

5153
@property
52-
def longitude(self):
54+
def longitude(self) -> float:
5355
"""The longitude value."""
5456
return self._longitude
5557

5658
@property
57-
def altitude(self):
59+
def altitude(self) -> float:
5860
"""The altitude value."""
5961
return self._altitude
6062

0 commit comments

Comments
 (0)