Clean up code: Replace exceptions, remove unused parameters, and fix type annotations in `Animation`, `ShowPartial`, `Create`, and `DrawBorderThenFill`
Overview: What does this pull request change?
This pull request introduces some improvements:
- Replace
NotImplementedErrortoTypeErrorfor invalid input type inShowPartial, Remove unused parameters and atrributes inDrawBorderThenFill, and Update return type annotation of_get_bounds()inShowPartialandCreate. - Fix typo of debug message in
Animation.__new__. - Removes
**kwargsfromAnimation.__init__, so it raisesTypeErrorimmediately when unknown arguments are passed. - Adds
_original__init__ = __init__toAnimationto preventAttributeErrorwhen using.set_default()with no arguments.
Motivation and Explanation: Why and how do your changes improve the library?
Explanation Point 1:
-
Replace
NotImplementedErrorwithTypeErrorinShowPartial. The docstring explicitly states it raisesTypeErrorwhen the input is notVMobject. -
In
DrawBorderThenFill, parameters and attributesdraw_border_animation_configandfill_animation_configare not used at all—they are just stored but never actually do anything. I double-checked withgit grepand 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_boundsreturn type annotation totuple[float, float]inShowPartialandCreate. The return value is used inpointwise_become_partial, which expects two floats.
Explanation Point 2: Only fix typo
Explanation Point 3:
- Remove
**kwargsand adduse_overridetoAnimation.__init__. So, it raises an exception (TypeError) immediately when unknown arguments are passed. Parameteruse_overrideis added to the__init__, so it will not be considered as unexpected argument when passed from subclass's constructor. Reasons: Currently,Animationsilently 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, runningCreate(Square(), rate_functions=linear)will pass silently, even thoughrate_functionsis not a valid argument. In contrast,MobjectraisesTypeErrorimmediately when unknown arguments are passed, likeSquare(say="Hello").# TypeError: Mobject.__init__() got an unexpected keyword argument 'say'NOTE:
Auto-completion for some default parameters from parent class in some animation classes, such asCreate, cannot work properly. For example, if we want to use therate_funcparameter and start typingrate, the auto-completion will suggestrate_functions, which is not a parameter (but a globally imported module). 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. - Remove unused
final_alpha_valueinTransformMatchingAbstractBaseas it 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=TAUis also removed because inRotatingthe parameter isradians,not angle, and the default value is alreadyTAU, so no problem removing it. Removing them is consistent with this PR because they are consideredunexpected keyword argument, andTypeErroris raised.
Explanation Point 4:
Adds _original__init__ to Animation.
The set_default() method uses cls._original__init__ to restore the original __init__ method when no keyword arguments are passed. However, _original__init__ is not defined in the Animation base class, which causes an error when set_default() is called directly on Animation.
Links to added or changed documentation pages
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