diff --git a/cq_editor/cq_utils.py b/cq_editor/cq_utils.py index 361bd854..95632ab6 100644 --- a/cq_editor/cq_utils.py +++ b/cq_editor/cq_utils.py @@ -49,6 +49,8 @@ def to_compound( vals.extend(obj.vals()) elif isinstance(obj, cq.Shape): vals.append(obj) + elif isinstance(obj, list) and not obj: + pass # an empty list produces an empty compound (see #600) elif isinstance(obj, list) and isinstance(obj[0], cq.Workplane): for o in obj: vals.extend(o.vals()) diff --git a/tests/test_cq_utils.py b/tests/test_cq_utils.py index 25601ea9..d545ff15 100644 --- a/tests/test_cq_utils.py +++ b/tests/test_cq_utils.py @@ -11,3 +11,12 @@ def test_to_compound_applies_sketch_placement(): assert f.Area() == pytest.approx(1) assert f.normalAt().toTuple() == pytest.approx((0, -1, 0)) + + +def test_to_compound_empty_list(): + # #600: to_compound([]) used to raise IndexError while type-checking obj[0]. + result = to_compound([]) + + assert isinstance(result, cq.Compound) + assert result.Solids() == [] + assert result.Faces() == []