-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Clean up code: Replace exceptions, remove unused parameters, and fix type annotations in Animation
, ShowPartial
, Create
, and DrawBorderThenFill
#4214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
irvanalhaq9
wants to merge
11
commits into
ManimCommunity:main
Choose a base branch
from
irvanalhaq9:cleanup-showpartial-animation-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains 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
…ibutes in DrawBorderThenFill and fix some return types.
…ent unexpected argument errors
for more information, see https://pre-commit.ci
….com/irvanalhaq9/manim into cleanup-showpartial-animation-config
ShowPartial
type check and remove unused parameters and attributes in DrawBorderThenFill
and fix some return types.Animation
, ShowPartial
, DrawBorderThenFill
and Create
Animation
, ShowPartial
, DrawBorderThenFill
and Create
Animation
, ShowPartial
, Create
, and DrawBorderThenFill
Animation
, ShowPartial
, Create
, and DrawBorderThenFill
ShowPartial
, Create
, and DrawBorderThenFill
ShowPartial
, Create
, and DrawBorderThenFill
ShowPartial
, Create
, and DrawBorderThenFill
ShowPartial
, Create
, and DrawBorderThenFill
Animation
, ShowPartial
, Create
, and DrawBorderThenFill
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?
This pull request introduces some improvements:
**kwargs
fromAnimation.__init__
, so it raisesTypeError
immediately when unknown arguments are passed.NotImplementedError
with a more appropriateTypeError
inShowPartial
.draw_border_animation_config
,fill_animation_config
) fromDrawBorderThenFill
._get_bounds
in bothShowPartial
andCreate
to better reflect actual usage.kwargs["final_alpha_value"] = 0
fromTransformMatchingAbstractBase
._original__init__ = __init__
to theAnimation
base class to preventAttributeError
when callingAnimation.set_default()
with no arguments.Motivation and Explanation: Why and how do your changes improve the library?
Currently,
Animation
silently accepts unexpected keyword arguments without raising an error. This behavior may lead to confusion or silent bugs, since the user might think the argument is doing something, when in fact it is not used at all. For example:This passes silently, even though
rate_functions
is not a valid argument.NOTE
For some animation classes, such as
Create
,FadeIn
,Rotate
, andTransform
, which define their own parameters, but rely on default values from the parent class for some parameters (by passing**kwargs
tosuper().__init__()
), auto-completion cannot work properly.For example, if you want to use the
rate_func
parameter and start typingrate
, the auto-completion may suggestrate_functions
, which is not a parameter, but a globally imported module in Manim. Users might mistakenly think that it's a valid parameter name, but the code won’t work as intended — and the problem is, Manim does not throw an error for that.In contrast,
Mobject
raises aTypeError
on unknown arguments:So, this PR makes it raise an exception (
TypeError
) immediately when unknown arguments are passed. In addition, it addsuse_override
to the__init__
to avoidTypeError
when passed from subclass's constructor.Replace
NotImplementedError
withTypeError
inShowPartial
NotImplementedError
, which was misleading since it’s clearly a type check.TypeError
, matching the docstring:Remove unused parameters and attributes from
DrawBorderThenFill
draw_border_animation_config
andfill_animation_config
are not used at all—they are just stored but never actually do anything. I double-checked withgit grep
and couldn't find any usage elsewhere. They're also unused in manimgl. So in this PR, I suggest removing them to keep things cleaner and less confusing.Verified with:
git grep output
$ git grep draw_border_animation_config manim/animation/creation.py: draw_border_animation_config: dict = {}, # what does this dict accept? manim/animation/creation.py: self.draw_border_animation_config = draw_border_animation_config $ git grep fill_animation_config manim/animation/creation.py: fill_animation_config: dict = {}, manim/animation/creation.py: self.fill_animation_config = fill_animation_config
Update
_get_bounds
return type annotation-> None
and-> tuple[int, float]
to-> tuple[float, float]
inShowPartial
andCreate
.pointwise_become_partial
, which expects two floats.Remove redundant
kwargs["final_alpha_value"] = 0
inTransformMatchingAbstractBase
final_alpha_value
is never read or used anywhere in the codebase (verified viagit grep
), and there is no documentation or comment about it. Removing it simplifies the code without affecting functionality.angle=TAU
is also removed because inRotating
the parameter isradians
,not angle
, and the default value isTAU
, so no problem removing it.Removing them is needed because from this PR, they are considered
unexpected keyword argument
, andTypeError
is raised.The
set_default()
method usescls._original__init__
to restore the original__init__
method when no keyword arguments are passed. However,_original__init__
is not defined in theAnimation
base class, which causes an error whenset_default()
is called directly onAnimation
. This fix ensures that the_original__init__
is always available, even in the base class.Links to added or changed documentation pages
Reviewer Checklist