diff --git a/src/build123d/operations_generic.py b/src/build123d/operations_generic.py index 72c86e2..2a2f007 100644 --- a/src/build123d/operations_generic.py +++ b/src/build123d/operations_generic.py @@ -963,9 +963,9 @@ def split( for obj in object_list: bottom = None if keep == Keep.BOTH: - top, bottom = obj.split(bisect_by, keep) # type: ignore[arg-type] + top, bottom = obj.split(bisect_by, keep) else: - top = obj.split(bisect_by, keep) # type: ignore[arg-type] + top = obj.split(bisect_by, keep) for subpart in [top, bottom]: if isinstance(subpart, Iterable): new_objects.extend(subpart) diff --git a/src/build123d/topology/shape_core.py b/src/build123d/topology/shape_core.py index c9822b7..3858e4a 100644 --- a/src/build123d/topology/shape_core.py +++ b/src/build123d/topology/shape_core.py @@ -1805,6 +1805,12 @@ class Shape(NodeMixin, Generic[TOPODS]): ]: """split and keep inside and outside""" + @overload + def split( + self, tool: TrimmingTool, keep: Literal[Keep.INSIDE, Keep.OUTSIDE] + ) -> None: + """invalid split""" + @overload def split(self, tool: TrimmingTool) -> Self | list[Self] | None: """split and keep inside (default)""" @@ -1834,6 +1840,9 @@ class Shape(NodeMixin, Generic[TOPODS]): if self._wrapped is None or not tool: raise ValueError("Can't split an empty edge/wire/tool") + if keep in [Keep.INSIDE, Keep.OUTSIDE]: + raise ValueError(f"{keep} is invalid") + shape_list = TopTools_ListOfShape() shape_list.Append(self.wrapped) @@ -1924,7 +1933,6 @@ class Shape(NodeMixin, Generic[TOPODS]): return top if keep == Keep.BOTTOM: return bottom - return None @overload def split_by_perimeter( diff --git a/tests/test_direct_api/test_shape.py b/tests/test_direct_api/test_shape.py index bb290e7..a261f8f 100644 --- a/tests/test_direct_api/test_shape.py +++ b/tests/test_direct_api/test_shape.py @@ -172,10 +172,11 @@ class TestShape(unittest.TestCase): self.assertEqual(len(top), 2) self.assertAlmostEqual(top[0].length, 3, 5) - def test_split_return_none(self): - shape = Box(1, 1, 1) - Pos((0, 0, -0.25)) * Box(1, 0.5, 0.5) - split_shape = shape.split(Plane.XY, keep=Keep.INSIDE) - self.assertIsNone(split_shape) + def test_split_invalid_keep(self): + with self.assertRaises(ValueError): + Box(1, 1, 1).split(Plane.XY, keep=Keep.INSIDE) + with self.assertRaises(ValueError): + Box(1, 1, 1).split(Plane.XY, keep=Keep.OUTSIDE) def test_split_by_perimeter(self): # Test 0 - extract a spherical cap