From 5894be7a14b76a002453894a42ed50e0d3dbf4a1 Mon Sep 17 00:00:00 2001 From: youdie006 Date: Fri, 14 Aug 2026 10:58:53 +0900 Subject: [PATCH] to_compound: return an empty compound for an empty list instead of raising to_compound() type-checked list inputs with isinstance(obj[0], ...) before handling the empty-list case, so to_compound([]) raised IndexError: list index out of range. This reached the object-tree render path (to_compound(node.obj).moved(...)) for an empty selection or intermediate result and crashed it. Handle an empty list explicitly, producing an empty compound (consistent with an empty Workplane). Add a regression test. Fixes #600 --- cq_editor/cq_utils.py | 2 ++ tests/test_cq_utils.py | 9 +++++++++ 2 files changed, 11 insertions(+) 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() == []