Skip to content

Commit b60b470

Browse files
committed
type stuff
1 parent 0b21289 commit b60b470

File tree

7 files changed

+42
-41
lines changed

7 files changed

+42
-41
lines changed

src/compas_rui/forms/about.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Optional
2+
13
import Eto.Forms # type: ignore
24
import Rhino.UI # type: ignore
35
import System # type: ignore
@@ -6,17 +8,16 @@
68
class AboutForm:
79
def __init__(
810
self,
9-
title, # type: str
10-
description, # type: str
11-
version, # type: str
12-
website, # type: str
13-
copyright, # type: str
14-
license, # type: str
15-
designers=None, # type: list[str] | None
16-
developers=None, # type: list[str] | None
17-
documenters=None, # type: list[str] | None
18-
):
19-
# type: (...) -> None
11+
title: str,
12+
description: str,
13+
version: str,
14+
website: str,
15+
copyright: str,
16+
license: str,
17+
designers: Optional[list[str]] = None,
18+
developers: Optional[list[str]] = None,
19+
documenters: Optional[list[str]] = None,
20+
) -> None:
2021
designers = designers or []
2122
developers = developers or []
2223
documenters = documenters or []

src/compas_rui/forms/namedvalues.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ class NamedValuesForm(Eto.Forms.Dialog[bool]):
3232

3333
def __init__(
3434
self,
35-
names, # type: list[str]
36-
values, # type: list
37-
title="Named Values", # type: str
38-
width=500, # type: int
39-
height=500, # type: int
40-
):
41-
# type: (...) -> None
42-
35+
names: list[str],
36+
values: list,
37+
title: str = "Named Values",
38+
width: int = 500,
39+
height: int = 500,
40+
) -> None:
4341
super().__init__()
4442

4543
def on_cell_formatting(sender, e):

src/compas_rui/forms/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def on_value_changed(sender, e):
4747
control = Eto.Forms.NumericUpDown()
4848
control.Value = value
4949
d = decimal.Decimal(str(value)).as_tuple()
50-
control.DecimalPlaces = -d.exponent
50+
control.DecimalPlaces = -d.exponent # type: ignore
5151
control.MaximumDecimalPlaces = 3
5252
control.MinValue = 0
5353
control.Increment = 1e-3
@@ -172,7 +172,7 @@ def add_items(parent, items):
172172
item = Eto.Forms.TreeGridItem()
173173
item.Values = (key, None, None)
174174
add_items(item.Children, value)
175-
parent.Add(item)
175+
parent.Add(item) # type: ignore
176176

177177
treecollection = Eto.Forms.TreeGridItemCollection()
178178
add_items(treecollection, settings.grouped_items)

src/compas_rui/rui.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import base64
2+
import errno
23
import json
34
import os
45
import uuid
@@ -180,7 +181,7 @@ def check(self):
180181
try:
181182
os.makedirs(os.path.dirname(self.filepath))
182183
except OSError as e:
183-
if e.errno != os.errno.EEXIST:
184+
if e.errno != errno.EEXIST:
184185
raise e
185186
if not os.path.exists(self.filepath):
186187
with open(self.filepath, "w+"):
@@ -201,7 +202,7 @@ def parse(self):
201202
raise NotImplementedError
202203

203204
def write(self):
204-
root = ET.tostring(self.root)
205+
root = ET.tostring(self.root) # type: ignore
205206
xml = minidom.parseString(root).toprettyxml(indent=" ")
206207
xml = "\n".join([line for line in xml.split("\n") if line.strip()])
207208
with open(self.filepath, "w+") as fh:

src/compas_rui/scene/meshobject.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def update_vertex_attributes(self, vertices: list[int], names: Optional[list[str
222222
names = names or sorted(self.mesh.default_vertex_attributes.keys())
223223
names = sorted([name for name in names if not name.startswith("_")])
224224

225-
values = self.mesh.vertex_attributes(vertices[0], names)
225+
values: list = self.mesh.vertex_attributes(vertices[0], names) # type: ignore
226226
if len(vertices) > 1:
227227
for i, name in enumerate(names):
228228
for vertex in vertices[1:]:
@@ -247,7 +247,7 @@ def update_face_attributes(self, faces: list[int], names: Optional[list[str]] =
247247
names = names or sorted(self.mesh.default_face_attributes.keys())
248248
names = sorted([name for name in names if not name.startswith("_")])
249249

250-
values = self.mesh.face_attributes(faces[0], names)
250+
values: list = self.mesh.face_attributes(faces[0], names) # type: ignore
251251
if len(faces) > 1:
252252
for i, name in enumerate(names):
253253
for face in faces[1:]:
@@ -272,7 +272,7 @@ def update_edge_attributes(self, edges: list[tuple[int, int]], names: Optional[l
272272
names = names or sorted(self.mesh.default_edge_attributes.keys())
273273
names = sorted([name for name in names if not name.startswith("_")])
274274

275-
values = self.mesh.edge_attributes(edges[0], names)
275+
values: list = self.mesh.edge_attributes(edges[0], names) # type: ignore
276276
if len(edges) > 1:
277277
for i, name in enumerate(names):
278278
for edge in edges[1:]:
@@ -301,8 +301,8 @@ def update_edge_attributes(self, edges: list[tuple[int, int]], names: Optional[l
301301
def move(self) -> bool:
302302
color = Rhino.ApplicationSettings.AppearanceSettings.FeedbackColor
303303

304-
vertex_p0 = {v: Rhino.Geometry.Point3d(*self.mesh.vertex_coordinates(v)) for v in self.mesh.vertices()}
305-
vertex_p1 = {v: Rhino.Geometry.Point3d(*self.mesh.vertex_coordinates(v)) for v in self.mesh.vertices()}
304+
vertex_p0 = {v: Rhino.Geometry.Point3d(*self.mesh.vertex_coordinates(v)) for v in self.mesh.vertices()} # type: ignore
305+
vertex_p1 = {v: Rhino.Geometry.Point3d(*self.mesh.vertex_coordinates(v)) for v in self.mesh.vertices()} # type: ignore
306306

307307
edges = list(self.mesh.edges())
308308

@@ -343,7 +343,8 @@ def OnDynamicDraw(sender, e):
343343
end = gp.Point()
344344
vector = compas_rhino.conversions.vector_to_compas(end - start)
345345

346-
for _, attr in self.mesh.vertices(True):
346+
attr: dict
347+
for _, attr in self.mesh.vertices(True): # type: ignore
347348
attr["x"] += vector[0]
348349
attr["y"] += vector[1]
349350
attr["z"] += vector[2]
@@ -363,7 +364,7 @@ def OnDynamicDraw(sender, e):
363364

364365
color = Rhino.ApplicationSettings.AppearanceSettings.FeedbackColor
365366
nbrs = [self.mesh.vertex_coordinates(nbr) for nbr in self.mesh.vertex_neighbors(vertex)]
366-
nbrs = [Rhino.Geometry.Point3d(*xyz) for xyz in nbrs]
367+
nbrs = [Rhino.Geometry.Point3d(*xyz) for xyz in nbrs] # type: ignore
367368

368369
gp = Rhino.Input.Custom.GetPoint()
369370

@@ -400,7 +401,7 @@ def OnDynamicDraw(sender, e):
400401
nbrs = self.mesh.vertex_neighbors(vertex)
401402
for nbr in nbrs:
402403
b = self.mesh.vertex_coordinates(nbr)
403-
line = [Rhino.Geometry.Point3d(*a), Rhino.Geometry.Point3d(*b)]
404+
line = [Rhino.Geometry.Point3d(*a), Rhino.Geometry.Point3d(*b)] # type: ignore
404405
if nbr in vertices:
405406
lines.append(line)
406407
else:
@@ -427,7 +428,7 @@ def OnDynamicDraw(sender, e):
427428
vector = compas_rhino.conversions.vector_to_compas(end - start)
428429

429430
for vertex in vertices:
430-
point = Point(*self.mesh.vertex_attributes(vertex, "xyz"))
431+
point = Point(*self.mesh.vertex_attributes(vertex, "xyz")) # type: ignore
431432
self.mesh.vertex_attributes(vertex, "xyz", point + vector)
432433
return True
433434

@@ -450,10 +451,10 @@ def OnDynamicDraw(sender, e):
450451
connectors = []
451452

452453
for vertex in vertices:
453-
a = Rhino.Geometry.Point3d(*self.mesh.vertex_coordinates(vertex))
454+
a = Rhino.Geometry.Point3d(*self.mesh.vertex_coordinates(vertex)) # type: ignore
454455
nbrs = self.mesh.vertex_neighbors(vertex)
455456
for nbr in nbrs:
456-
b = Rhino.Geometry.Point3d(*self.mesh.vertex_coordinates(nbr))
457+
b = Rhino.Geometry.Point3d(*self.mesh.vertex_coordinates(nbr)) # type: ignore
457458
if nbr in vertices:
458459
lines.append((a, b))
459460
else:
@@ -487,9 +488,9 @@ def OnDynamicDraw(sender, e):
487488
gp.DynamicDraw += OnDynamicDraw
488489

489490
if direction in ("x", "y", "z"):
490-
gp.Constrain(geometry)
491+
gp.Constrain(geometry) # type: ignore
491492
else:
492-
gp.Constrain(geometry, False)
493+
gp.Constrain(geometry, False) # type: ignore
493494

494495
gp.Get()
495496

src/compas_rui/values/dictvalue.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def _check_dict_value_type(self, value):
1414
if not isinstance(k, str):
1515
raise ValueError("Dict key {} is not of type {}".format(k, str))
1616

17-
if not isinstance(v, self.dict_value_type):
17+
if self.dict_value_type and not isinstance(v, self.dict_value_type):
1818
raise ValueError("Dict value {}:{} is not of type {}".format(k, v, self.dict_value_type))
1919

2020
def check(self, value):
@@ -25,7 +25,7 @@ def __getitem__(self, key):
2525
return self.value[key]
2626

2727
def __setitem__(self, key, value):
28-
if not isinstance(value, self.dict_value_type):
28+
if self.dict_value_type and not isinstance(value, self.dict_value_type):
2929
raise ValueError("New value {} is not of type {}".format(value, self.dict_value_type))
3030

3131
self.value[key] = value
@@ -39,7 +39,7 @@ def data(self):
3939
return {
4040
"value": self.value,
4141
"value_type": "dict",
42-
"dict_value_type": self.dict_value_type.__name__,
42+
"dict_value_type": self.dict_value_type.__name__ if self.dict_value_type else None,
4343
}
4444

4545
@data.setter

src/compas_rui/values/listvalue.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, value=None, list_value_type=None):
1111

1212
def _check_list_value_type(self, value):
1313
for i, item in enumerate(value):
14-
if not isinstance(item, self.list_value_type):
14+
if self.list_value_type and not isinstance(item, self.list_value_type):
1515
raise ValueError("List item {}:{} is not of type {}".format(i, item, self.list_value_type))
1616

1717
def check(self, value):
@@ -28,7 +28,7 @@ def data(self):
2828
"value": self.value,
2929
"value_type": "list",
3030
"options": self.options,
31-
"list_value_type": self.list_value_type.__name__,
31+
"list_value_type": self.list_value_type.__name__ if self.list_value_type else None,
3232
}
3333

3434
@data.setter

0 commit comments

Comments
 (0)