diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py index a7bb5ac4f4..b50a683720 100644 --- a/manim/mobject/types/vectorized_mobject.py +++ b/manim/mobject/types/vectorized_mobject.py @@ -2856,8 +2856,9 @@ def point_from_proportion(self, alpha: float) -> Point3D: def _throw_error_if_no_submobjects(self): if len(self.submobjects) == 0: caller_name = sys._getframe(1).f_code.co_name + cls = type(self).__name__ raise Exception( - f"Cannot call CurvesAsSubmobjects. {caller_name} for a CurvesAsSubmobject with no submobjects" + f"Cannot call {cls}.{caller_name} for a {cls} with no submobjects" ) def _get_submobjects_with_points(self): @@ -2866,8 +2867,9 @@ def _get_submobjects_with_points(self): ) if len(submobjs_with_pts) == 0: caller_name = sys._getframe(1).f_code.co_name + cls = type(self).__name__ raise Exception( - f"Cannot call CurvesAsSubmobjects. {caller_name} for a CurvesAsSubmobject whose submobjects have no points" + f"Cannot call {cls}.{caller_name} for a {cls} 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..99e17d9b92 100644 --- a/tests/module/mobject/types/vectorized_mobject/test_vectorized_mobject.py +++ b/tests/module/mobject/types/vectorized_mobject/test_vectorized_mobject.py @@ -192,6 +192,28 @@ def test_curves_as_submobjects_point_from_proportion(): np.testing.assert_array_equal(obj.point_from_proportion(0.5), np.array([3, 0, 0])) +def test_curves_as_submobjects_error_messages_use_the_actual_class_name(): + class DerivedCurves(CurvesAsSubmobjects): + pass + + obj = DerivedCurves(VGroup()) + + with pytest.raises( + Exception, + match=r"Cannot call DerivedCurves\.point_from_proportion for a " + r"DerivedCurves with no submobjects", + ): + obj.point_from_proportion(0) + + obj.add(VMobject()) + with pytest.raises( + Exception, + match=r"Cannot call DerivedCurves\.point_from_proportion for a " + r"DerivedCurves whose submobjects have no points", + ): + obj.point_from_proportion(0) + + def test_vgroup_init(): """Test the VGroup instantiation.""" VGroup()