diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py index 8d05268539..b5efeef820 100644 --- a/manim/mobject/types/vectorized_mobject.py +++ b/manim/mobject/types/vectorized_mobject.py @@ -2859,7 +2859,8 @@ def _throw_error_if_no_submobjects(self): if len(self.submobjects) == 0: caller_name = sys._getframe(1).f_code.co_name raise Exception( - f"Cannot call CurvesAsSubmobjects. {caller_name} for a CurvesAsSubmobject with no submobjects" + f"Cannot call {type(self).__name__}.{caller_name} " + f"for a {type(self).__name__} with no submobjects" ) def _get_submobjects_with_points(self): @@ -2869,7 +2870,8 @@ def _get_submobjects_with_points(self): if len(submobjs_with_pts) == 0: caller_name = sys._getframe(1).f_code.co_name raise Exception( - f"Cannot call CurvesAsSubmobjects. {caller_name} for a CurvesAsSubmobject whose submobjects have no points" + f"Cannot call {type(self).__name__}.{caller_name} " + f"for a {type(self).__name__} whose submobjects have no points" ) return submobjs_with_pts diff --git a/tests/module/mobject/types/vectorized_mobject/test_vectorized_mobject.py b/tests/module/mobject/types/vectorized_mobject/test_vectorized_mobject.py index 4e083611a6..c304abf8c9 100644 --- a/tests/module/mobject/types/vectorized_mobject/test_vectorized_mobject.py +++ b/tests/module/mobject/types/vectorized_mobject/test_vectorized_mobject.py @@ -774,3 +774,26 @@ def test_pointwise_become_partial_where_vmobject_is_self(): ] ) np.testing.assert_allclose(sq.points, expected_points) + + +@pytest.mark.parametrize("use_subclass", [False, True]) +@pytest.mark.parametrize("empty_child", [False, True]) +def test_curves_as_submobjects_errors_use_actual_class(use_subclass, empty_child): + class CustomCurves(CurvesAsSubmobjects): + pass + + curves_class = CustomCurves if use_subclass else CurvesAsSubmobjects + curves = curves_class(VGroup()) + if empty_child: + curves.add(VMobject()) + + with pytest.raises(Exception) as error: + curves.point_from_proportion(0) + + reason = ( + "whose submobjects have no points" if empty_child else "with no submobjects" + ) + class_name = curves_class.__name__ + assert str(error.value) == ( + f"Cannot call {class_name}.point_from_proportion for a {class_name} {reason}" + )