Skip to content

Commit f9f5ffe

Browse files
Fixing color_packet.py
To avoid the dreaded Liskov Substitution Principle (thanks to mypy's fastidiousness)..
1 parent d5ee528 commit f9f5ffe

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

adafruit_bluefruit_connect/color_packet.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from .packet import Packet
2020

2121
try:
22-
from typing import Optional # adjust these as needed
22+
from typing import Optional, Tuple # adjust these as needed
2323
except ImportError:
2424
pass
2525

@@ -33,22 +33,22 @@ class ColorPacket(Packet):
3333
_FMT_CONSTRUCT: str = "<2s3B"
3434
_TYPE_HEADER: bytes = b"!C"
3535

36-
def __init__(self, color: Optional[Packet]) -> None:
36+
def __init__(self, color: Tuple) -> None:
3737
"""Construct a ColorPacket from a 3-element :class:`tuple` of RGB
3838
values, or from an int color value 0xRRGGBB.
3939
4040
:param tuple/int color: an RGB :class:`tuple` ``(red, green, blue)``
4141
or an int color value ``0xRRGGBB``
4242
"""
4343
if isinstance(color, int):
44-
self._color = tuple(color.to_bytes(3, "big"))
44+
self._color: Tuple = tuple(color.to_bytes(3, "big"))
4545
elif len(color) == 3 and all(0 <= c <= 255 for c in color):
4646
self._color = color
4747
else:
4848
raise ValueError("Color must be an integer 0xRRGGBB or a tuple(r,g,b)")
4949

5050
@classmethod
51-
def parse_private(cls, packet: Optional[Packet]) -> Optional[Packet]:
51+
def parse_private(cls, packet: bytes) -> Optional[Packet]:
5252
"""Construct a ColorPacket from an incoming packet.
5353
Do not call this directly; call Packet.from_bytes() instead.
5454
pylint makes it difficult to call this method _parse(), hence the name.

0 commit comments

Comments
 (0)