Derive the class name in CurvesAsSubmobjects error messages - #4995
Open
cqxswbc2 wants to merge 1 commit into
Open
Derive the class name in CurvesAsSubmobjects error messages#4995cqxswbc2 wants to merge 1 commit into
cqxswbc2 wants to merge 1 commit into
Conversation
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`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview: What does this pull request change?
Closes #4983.
CurvesAsSubmobjects._throw_error_if_no_submobjectsand_get_submobjects_with_pointsboth hardcoded the class name in the exception theyraise, 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
CurvesAsSubmobjectscurrently reports the base class name, whichpoints 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 otherCurvesAsSubmobjectwithout the trailing "s".Both now read
Cannot call {cls}.{caller_name} for a {cls} ..., which matches theconvention already used by
Mobject.throw_error_if_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_proportionmatches on thewith no submobjectsand
have no pointsfragments, 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.pygives 43 passed. The new test fails on
mainwithruff checkandruff format --checkare clean on both changed files.Reviewer Checklist