Skip to content

Derive the class name in CurvesAsSubmobjects error messages - #4995

Open
cqxswbc2 wants to merge 1 commit into
ManimCommunity:mainfrom
cqxswbc2:fix/curves-as-submobjects-error-class-name
Open

Derive the class name in CurvesAsSubmobjects error messages#4995
cqxswbc2 wants to merge 1 commit into
ManimCommunity:mainfrom
cqxswbc2:fix/curves-as-submobjects-error-class-name

Conversation

@cqxswbc2

@cqxswbc2 cqxswbc2 commented Sep 7, 2026

Copy link
Copy Markdown

Overview: What does this pull request change?

Closes #4983.

CurvesAsSubmobjects._throw_error_if_no_submobjects and
_get_submobjects_with_points both hardcoded the class name in the exception they
raise, so the messages are derived from type(self).__name__ instead.

Motivation and Explanation: Why and how do your changes improve the library?

A subclass of CurvesAsSubmobjects currently reports the base class name, which
points readers at the wrong class, and the strings would silently go stale if the
class were ever renamed. The two messages also disagreed with each other: one said
CurvesAsSubmobjects, the other CurvesAsSubmobject without the trailing "s".

Both now read Cannot call {cls}.{caller_name} for a {cls} ..., which matches the
convention already used by Mobject.throw_error_if_no_points:

caller_name = sys._getframe(1).f_code.co_name
cls = type(self).__name__
message = f"Cannot call {cls}.{caller_name} because {self!r} has no points."

As a side effect this also removes the stray space that made the old message read
as Cannot call CurvesAsSubmobjects. point_from_proportion ....

The added test defines a subclass and asserts that both error paths name it, so the
regression cannot come back unnoticed. The existing
test_curves_as_submobjects_point_from_proportion matches on the with no submobjects
and have no points fragments, which are unchanged, so it still passes.

Links to added or changed documentation pages

None; the error strings are not quoted in the docs.

Further Information and Comments

Verified locally on Windows with Python 3.13:
pytest tests/module/mobject/types/vectorized_mobject/test_vectorized_mobject.py
gives 43 passed. The new test fails on main with

Expected regex: 'Cannot call DerivedCurves\.point_from_proportion for a DerivedCurves with no submobjects'
Actual message: 'Cannot call CurvesAsSubmobjects. point_from_proportion for a CurvesAsSubmobject with no submobjects'

ruff check and ruff format --check are clean on both changed files.

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

Both error paths hardcoded the class name, so subclasses reported
`CurvesAsSubmobjects` instead of their own name, and the messages would
silently go stale if the class were ever renamed. The two strings also
disagreed with each other, one of them dropping the trailing "s".

Use `type(self).__name__`, matching the convention already used by
`Mobject.throw_error_if_no_points`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CurvesAsSubmobjects error messages contain hardcoded class names

1 participant