Skip to content

Commit ea5e94e

Browse files
committed
Assert some types in animation base
1 parent f446c5a commit ea5e94e

File tree

1 file changed

+25
-15
lines changed
  • src/bloqade/visual/animation

1 file changed

+25
-15
lines changed

src/bloqade/visual/animation/base.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,20 @@ def get_artists(self) -> Tuple[Any]:
4545
class GlobalGateArtist(GateArtist):
4646
mpl_obj: mpatches.Rectangle
4747

48-
def __init__(self, mpl_ax: Any, xmin, ymin, width, height, color):
48+
def __init__(
49+
self, mpl_ax: Any, xmin: float, ymin: float, width: float, height: float, color
50+
):
4951
super().__init__(mpl_ax)
5052
rc = mpatches.Rectangle(
51-
[xmin, ymin], width, height, color=color, alpha=0.6, visible=False
53+
(xmin, ymin), width, height, color=color, alpha=0.6, visible=False
5254
)
5355
mpl_ax.add_patch(rc)
5456
self.mpl_obj = rc
5557

5658
def clear_data(self) -> None:
5759
self.mpl_obj.set_width(0)
5860
self.mpl_obj.set_height(0)
59-
self.mpl_obj.set_xy([0, 0])
61+
self.mpl_obj.set_xy((0, 0))
6062

6163
def get_artists(self) -> Tuple[Any]:
6264
return (self.mpl_obj,)
@@ -86,7 +88,7 @@ def __init__(
8688
self.width = width
8789
self.xmin = xmin
8890
rc_btm = mpatches.Rectangle(
89-
[xmin, ymin_keepout],
91+
(xmin, ymin_keepout),
9092
width,
9193
ymin - ymin_keepout,
9294
color=color,
@@ -97,13 +99,13 @@ def __init__(
9799
self.mpl_obj_keepout_btm = rc_btm
98100

99101
rc = mpatches.Rectangle(
100-
[xmin, ymin], width, ymax - ymin, color=color, alpha=0.6, visible=False
102+
(xmin, ymin), width, ymax - ymin, color=color, alpha=0.6, visible=False
101103
)
102104
mpl_ax.add_patch(rc)
103105
self.mpl_obj = rc
104106

105107
rc_top = mpatches.Rectangle(
106-
[xmin, ymax],
108+
(xmin, ymax),
107109
width,
108110
ymax_keepout - ymax,
109111
color=color,
@@ -116,31 +118,31 @@ def __init__(
116118
def clear_data(self) -> None:
117119
self.mpl_obj.set_width(0)
118120
self.mpl_obj.set_height(0)
119-
self.mpl_obj.set_xy([0, 0])
121+
self.mpl_obj.set_xy((0, 0))
120122

121123
self.mpl_obj_keepout_top.set_width(0)
122124
self.mpl_obj_keepout_top.set_height(0)
123-
self.mpl_obj_keepout_top.set_xy([0, 0])
125+
self.mpl_obj_keepout_top.set_xy((0, 0))
124126

125127
self.mpl_obj_keepout_btm.set_width(0)
126128
self.mpl_obj_keepout_btm.set_height(0)
127-
self.mpl_obj_keepout_btm.set_xy([0, 0])
129+
self.mpl_obj_keepout_btm.set_xy((0, 0))
128130

129-
def get_artists(self) -> Tuple[Any]:
131+
def get_artists(self) -> Tuple[Any, ...]:
130132
return (self.mpl_obj, self.mpl_obj_keepout_top, self.mpl_obj_keepout_btm)
131133

132134
def update_data(self, ymin, ymax, ymin_keepout, ymax_keepout):
133135
self.mpl_obj.set_height(ymax - ymin)
134136
self.mpl_obj.set_width(self.width)
135-
self.mpl_obj.set_xy([self.xmin, ymin])
137+
self.mpl_obj.set_xy((self.xmin, ymin))
136138

137139
self.mpl_obj_keepout_top.set_height(ymax_keepout - ymax)
138140
self.mpl_obj_keepout_top.set_width(self.width)
139-
self.mpl_obj_keepout_top.set_xy([self.xmin, ymax])
141+
self.mpl_obj_keepout_top.set_xy((self.xmin, ymax))
140142

141143
self.mpl_obj_keepout_btm.set_height(ymin - ymin_keepout)
142144
self.mpl_obj_keepout_btm.set_width(self.width)
143-
self.mpl_obj_keepout_btm.set_xy([self.xmin, ymin_keepout])
145+
self.mpl_obj_keepout_btm.set_xy((self.xmin, ymin_keepout))
144146

145147
def set_visible(self, visible: bool):
146148
self.mpl_obj.set_visible(visible)
@@ -194,11 +196,19 @@ def not_defined(self):
194196
)
195197

196198
@property
197-
def width(self):
199+
def width(self) -> float:
200+
if self.xmax is None or self.xmin is None:
201+
raise ValueError(
202+
"Can't return width of FOV as either xmin or xmax are undefined"
203+
)
198204
return self.xmax - self.xmin
199205

200206
@property
201-
def height(self):
207+
def height(self) -> float:
208+
if self.ymax is None or self.ymin is None:
209+
raise ValueError(
210+
"Can't return width of FOV as either ymin or ymax are undefined"
211+
)
202212
return self.ymax - self.ymin
203213

204214
def to_json(self):

0 commit comments

Comments
 (0)