mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-17 02:49:12 +00:00
Fix all ty diagnostics on ifcviewer-wgpu (ci-lint ty-ios + ty-bonsai)
This branch carried v0.8.0's strict `[tool.ty.rules] all = "error"` config but not the source fixes that were made upstream to satisfy it, so both ci-lint ty gates were failing: `poe ty-ios` reported 256 diagnostics and `poe ty-bonsai` 258. Both are now clean. Most fixes are ported from v0.8.0 and follow two idioms: initialise a name before a conditional that may not bind it (plus an `assert` where the invariant is real but not provable), and close an exhaustive `if`/`elif` chain with `else: assert False, <discriminant>`. The branch's own newer accessors are preserved throughout - `.file`, `.declaration`, `file.types()`, `get_max_id()` are kept rather than reverted to `wrapped_data.*`, and non-ty upstream changes (notably the in-progress geometry cache removal) are deliberately not pulled in. Notable fixes that are not straight ports: * ifcopenshell_wrapper.pyi: `entity_instance.file` was declared as `def file(self) -> file`, where the property name shadows the `class file` below it, so the annotation resolved to `Unknown`. Every `element.file` in the codebase was therefore unchecked. Qualifying it to `ifcopenshell.file` restores `.schema` to its Literal union and surfaces no new diagnostics. * model/wall.py: a duplicated merge fragment in the void-straddle path ran an always-true `if void_straddles:` that read `new_opening` from the mutually exclusive branch (stale value, or NameError on the first iteration), followed by an unreachable duplicate `elif`. Removing it makes the file match v0.8.0. * light/operator.py: upstream's own fix unpacks three targets from two values and raises ValueError unconditionally; corrected to `None, None, None`. * assign_system.py, validate.py, geom/main.py: walrus-in-genexp is valid at runtime (PEP 572 binds in the containing scope) but ty does not model it; rewritten as explicit loops, matching upstream. Verified: poe ty-ios, poe ty-bonsai, ruff check src/ nix/, black --check ., and compileall -W error at py3.10 (ifcopenshell-python) and py3.11 (bonsai). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,10 +27,12 @@ flatten = itertools.chain.from_iterable
|
||||
|
||||
def get_element_data(model, name, element):
|
||||
if element["geometry_type"] == "Edge":
|
||||
cell_tags, cell_block = None, None
|
||||
for i, cell_block in enumerate(model.cells):
|
||||
if cell_block.type == "line":
|
||||
cell_tags = model.cell_data["cell_tags"][i]
|
||||
break
|
||||
assert cell_tags is not None and cell_block is not None
|
||||
rows = []
|
||||
for i_row, i in enumerate(cell_tags):
|
||||
if i == 0:
|
||||
@@ -59,6 +61,7 @@ def get_element_data(model, name, element):
|
||||
elif element["geometry_type"] == "Face":
|
||||
triangle_cell_tags = None
|
||||
quad_cell_tags = None
|
||||
points, cell_block = None, None
|
||||
for i, cell_block in enumerate(model.cells):
|
||||
if cell_block.type == "triangle":
|
||||
triangle_cell_tags = model.cell_data["cell_tags"][i]
|
||||
@@ -78,8 +81,10 @@ def get_element_data(model, name, element):
|
||||
if not len(rows):
|
||||
points = []
|
||||
else:
|
||||
assert cell_block is not None
|
||||
points = list(flatten([cell_block.data[c] for c in rows]))
|
||||
|
||||
cell_block = None
|
||||
for i, cell_block in enumerate(model.cells):
|
||||
if cell_block.type == "quad":
|
||||
quad_cell_tags = model.cell_data["cell_tags"][i]
|
||||
@@ -97,6 +102,7 @@ def get_element_data(model, name, element):
|
||||
rows.append(i_row)
|
||||
break
|
||||
if len(rows):
|
||||
assert cell_block is not None and points is not None
|
||||
points.extend(list(flatten([cell_block.data[c] for c in rows])))
|
||||
|
||||
points = list(set(points))
|
||||
@@ -172,6 +178,8 @@ def results_to_ifc(ifc_file, ifc_model, rmed_path, global_case, field_types, dat
|
||||
model_cases = data["load_cases"]
|
||||
elif global_case == "COMB":
|
||||
model_cases = data["load_combinations"]
|
||||
else:
|
||||
assert False, global_case
|
||||
for field in field_types:
|
||||
if field == "InternalForces":
|
||||
_parsed_data = internal_forces_to_ifc(ifc_file, ifc_model, result, model_cases, data["elements"])
|
||||
|
||||
+19
-2
@@ -283,7 +283,7 @@ class Ifc2CA:
|
||||
geometry = [x.EdgeStart.VertexGeometry.Coordinates for x in repr_item.Bounds[0].Bound.EdgeList]
|
||||
|
||||
else:
|
||||
print(representation)
|
||||
assert False, representation
|
||||
return geometry
|
||||
|
||||
def parse_material(self, material: ios.entity_instance):
|
||||
@@ -399,6 +399,9 @@ class Ifc2CA:
|
||||
elif element.is_a("IfcStructuralSurfaceMember"):
|
||||
placement = ifcopenshell.util.placement.get_axis2placement(repr_item.FaceSurface.Position)
|
||||
|
||||
else:
|
||||
assert False, element
|
||||
|
||||
origin, orientation = self.parse_transformation_matrix(placement)
|
||||
data["origin"] = origin
|
||||
data["orientation"] = orientation
|
||||
@@ -436,7 +439,7 @@ class Ifc2CA:
|
||||
for i, v in enumerate(placement[:3]):
|
||||
v[3] = data["geometry"][i]
|
||||
|
||||
if connection.is_a("IfcStructuralCurveConnection"):
|
||||
elif connection.is_a("IfcStructuralCurveConnection"):
|
||||
placement = ifcopenshell.util.placement.a2p(
|
||||
data["geometry"][0],
|
||||
connection.Axis.DirectionRatios,
|
||||
@@ -446,6 +449,9 @@ class Ifc2CA:
|
||||
elif connection.is_a("IfcStructuralSurfaceConnection"):
|
||||
placement = ifcopenshell.util.placement.get_axis2placement(repr_item.FaceSurface.Position)
|
||||
|
||||
else:
|
||||
assert False, connection
|
||||
|
||||
origin, orientation = self.parse_transformation_matrix(placement)
|
||||
data["origin"] = origin
|
||||
data["orientation"] = orientation
|
||||
@@ -552,6 +558,9 @@ class Ifc2CA:
|
||||
},
|
||||
}
|
||||
|
||||
else:
|
||||
assert False, element["geometry_type"]
|
||||
|
||||
for action in actions:
|
||||
self.add_action_loads(element, action, data, load_cases)
|
||||
|
||||
@@ -586,6 +595,7 @@ class Ifc2CA:
|
||||
|
||||
data["actions"].append(action.get_info() | {"AppliedLoad": action.AppliedLoad.get_info()})
|
||||
if element["geometry_type"] in ["Vertex", "Edge"]:
|
||||
force_projection_coeff, moment_projection_coeff = None, None
|
||||
if action.is_a("IfcStructuralPointAction") and load.is_a("IfcStructuralLoadSingleForce"):
|
||||
FX = tempFX = load.ForceX if load.ForceX is not None else 0.0
|
||||
FY = tempFY = load.ForceY if load.ForceY is not None else 0.0
|
||||
@@ -639,8 +649,12 @@ class Ifc2CA:
|
||||
force_projection_coeff = 1.0
|
||||
moment_projection_coeff = 1.0
|
||||
|
||||
else:
|
||||
assert False, action
|
||||
|
||||
for iLC, load_case in enumerate(load_cases):
|
||||
if load_case.id() in active_load_case_ids:
|
||||
assert force_projection_coeff is not None and moment_projection_coeff is not None
|
||||
load_case_coeff = 1.0 if load_case.Coefficient is None else load_case.Coefficient
|
||||
data["loadGroups"].append(load_group.Name)
|
||||
data["loadsLC"]["FX"][iLC] += FX * load_group_coeff * load_case_coeff * force_projection_coeff
|
||||
@@ -672,6 +686,9 @@ class Ifc2CA:
|
||||
else:
|
||||
force_projection_coeff = 1.0
|
||||
|
||||
else:
|
||||
assert False, action
|
||||
|
||||
for iLC, load_case in enumerate(load_cases):
|
||||
if load_case.id() in active_load_case_ids:
|
||||
load_case_coeff = 1.0 if load_case.Coefficient is None else load_case.Coefficient
|
||||
|
||||
Reference in New Issue
Block a user