Skip to content

Commit e49d93e

Browse files
authored
SEVERAL exceptions because pylint can't take the hint
I mean seriously, how old is this bug? pylint-dev/pylint#1498
1 parent 2b591d4 commit e49d93e

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

buildhat/matrix.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .devices import Device
22
from .exc import MatrixError
3+
from typing import List, Any, Tuple
34

45

56
class Matrix(Device):
@@ -14,7 +15,7 @@ def __init__(self, port):
1415
self.mode(2)
1516
self._matrix = [[(0, 0) for x in range(3)] for y in range(3)]
1617

17-
def set_pixels(self, matrix, display=True):
18+
def set_pixels(self, matrix: List[List[Tuple[Any, int]]], display=True):
1819
"""Write pixel data to LED matrix
1920
2021
:param pixels: 3x3 list of tuples, with colour (0–10) and brightness (0–10) (see example for more detail)
@@ -26,7 +27,7 @@ def set_pixels(self, matrix, display=True):
2627
if len(matrix[x]) != 3:
2728
raise MatrixError("Incorrect matrix width")
2829
for y in range(3):
29-
matrix[x][y] = Matrix.normalize_pixel(matrix[x][y])
30+
matrix[x][y] = Matrix.normalize_pixel(matrix[x][y]) # pylint: disable=too-many-function-args
3031
self._matrix = matrix
3132
if display:
3233
self._output()
@@ -40,6 +41,7 @@ def _output(self):
4041
self._write1(out)
4142
self.deselect()
4243

44+
@classmethod
4345
def strtocolor(colorstr):
4446
"""Return the BuldHAT's integer representation of a color string
4547
@@ -71,18 +73,19 @@ def strtocolor(colorstr):
7173
return 0
7274
raise MatrixError("Invalid color specified")
7375

74-
def normalize_pixel(pixel):
76+
@classmethod
77+
def normalize_pixel(pixel: Tuple[Any, int]):
7578
"""Validate a pixel tuple (color, brightness) and convert string colors to integers
7679
7780
:param pixel: tuple of colour (0–10) or string (ie:"red") and brightness (0–10)
7881
:return: (color, brightness) integers
7982
:rtype: tuple
8083
"""
8184
if isinstance(pixel, tuple):
82-
c, brightness = pixel
85+
c, brightness = pixel # pylint: disable=unpacking-non-sequence
8386
if isinstance(c, str):
84-
c = Matrix.strtocolor(c)
85-
if not ( isinstance(brightness, int) and isinstance(c, int)):
87+
c = Matrix.strtocolor(c) # pylint: disable=too-many-function-args
88+
if not (isinstance(brightness, int) and isinstance(c, int)):
8689
raise MatrixError("Invalid pixel specified")
8790
if not (brightness >= 0 and brightness <= 10):
8891
raise MatrixError("Invalid brightness value specified")
@@ -92,28 +95,30 @@ def normalize_pixel(pixel):
9295
else:
9396
raise MatrixError("Invalid pixel specified")
9497

95-
def validate_coordinate(coord):
98+
@classmethod
99+
def validate_coordinate(coord: Tuple[int, int]):
96100
""""Validate an x,y coordinate for the 3x3 Matrix
97101
98102
:param coord: tuple of 0-2 for the X coordinate and 0-2 for the Y coordinate
99103
"""
104+
# pylint: disable=unsubscriptable-object
100105
if isinstance(coord, tuple):
101106
if not (isinstance(coord[0], int) and isinstance(coord[1], int)):
102107
raise MatrixError("Invalid coord specified")
103108
elif coord[0] > 2 or coord[0] < 0 or coord[1] > 2 or coord[1] < 0:
104-
raise MatrixError("Invalid coord specified")
109+
raise MatrixError("Invalid coord specified")
105110
else:
106111
raise MatrixError("Invalid coord specified")
107112

108-
def clear(self, pixel=None):
113+
def clear(self, pixel: Tuple[Any, int] = None):
109114
"""Clear matrix or set all as the same pixel
110115
111116
:param pixel: tuple of colour (0–10) or string and brightness (0–10)
112117
"""
113118
if pixel is None:
114119
self._matrix = [[(0, 0) for x in range(3)] for y in range(3)]
115120
else:
116-
color = Matrix.normalize_pixel(pixel)
121+
color = Matrix.normalize_pixel(pixel) # pylint: disable=too-many-function-args
117122
self._matrix = [[color for x in range(3)] for y in range(3)]
118123
self._output()
119124

@@ -172,15 +177,15 @@ def set_transition(self, transition):
172177
self.mode(2) # The rest of the Matrix code seems to expect this to be always set
173178
self.deselect()
174179

175-
def set_pixel(self, coord, pixel, display=True):
180+
def set_pixel(self, coord: Tuple[int, int], pixel: Tuple[Any, int], display=True):
176181
"""Write pixel to coordinate
177182
178183
:param coord: (0,0) to (2,2)
179184
:param pixel: tuple of colour (0–10) or string and brightness (0–10)
180185
:param display: Whether to update matrix or not
181186
"""
182-
color = Matrix.normalize_pixel(pixel)
183-
Matrix.validate_coordinate(coord)
187+
color = Matrix.normalize_pixel(pixel) # pylint: disable=too-many-function-args
188+
Matrix.validate_coordinate(coord) # pylint: disable=too-many-function-args
184189
x, y = coord
185190
self._matrix[x][y] = color
186191
if display:

0 commit comments

Comments
 (0)