| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…ising 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 CadQuery#600
| Back | FazBrowse Home | New Git URL |
Fixes #600.
Problem
to_compound() type-checks list inputs by indexing obj[0] before it handles the empty-list case:
So to_compound([]) raises IndexError: list index out of range. This is on a live render path: cq_editor/widgets/object_tree.py calls to_compound(node.obj).moved(world), so an empty selection or an empty intermediate result crashes the object-tree/assembly render.
Fix
Handle an empty list explicitly and return an empty compound, which is consistent with how an empty Workplane (whose vals() is empty) already flows through cq.Compound.makeCompound([]). I confirmed cq.Compound.makeCompound([]) returns an empty Compound rather than raising.
(The issue left the choice open between an empty compound and a raised error; empty compound keeps to_compound total over its declared input types and matches the empty-Workplane behavior. Happy to switch to a ValueError if you'd prefer.)
Test
Added test_to_compound_empty_list in tests/test_cq_utils.py. Red-green verified with pytest tests/test_cq_utils.py: before the change the test raises IndexError; after, to_compound([]) returns an empty cq.Compound. The existing test_cq_utils.py test still passes.
Disclosure: I used AI assistance (Claude) while preparing this change. I reproduced the crash, ran the tests (red-green), and take responsibility for the contribution.