A community-maintained Python framework for creating mathematical animations.
Improved handling of attributes when using the ``.animate`` syntax (#2665)
Benjamin Hacklb6311098df07
diff --git a/manim/animation/transform.py b/manim/animation/transform.pyindex 22d2a65d1..624d36f00 100644--- a/manim/animation/transform.py+++ b/manim/animation/transform.py@@ -360,6 +360,11 @@ class _MethodAnimation(MoveToTarget):self.methods = methodssuper().__init__(mobject)+ def finish(self) -> None:+ for method, method_args, method_kwargs in self.methods:+ method.__func__(self.mobject, *method_args, **method_kwargs)+ super().finish()+class ApplyMethod(Transform):"""Animates a mobject by applying a method.diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.pyindex 63869698a..74bf28539 100644--- a/manim/mobject/mobject.py+++ b/manim/mobject/mobject.py@@ -2783,7 +2783,6 @@ class _AnimationBuilder:def __getattr__(self, method_name):method = getattr(self.mobject.target, method_name)- self.methods.append(method)has_overridden_animation = hasattr(method, "_override_animate")if (self.is_chaining and has_overridden_animation) or self.overridden_animation:@@ -2801,6 +2800,7 @@ class _AnimationBuilder:**method_kwargs,)else:+ self.methods.append([method, method_args, method_kwargs])method(*method_args, **method_kwargs)return selfdiff --git a/tests/test_scene_rendering/test_play_logic.py b/tests/test_scene_rendering/test_play_logic.pyindex 7f996ff3f..9a8e44bea 100644--- a/tests/test_scene_rendering/test_play_logic.py+++ b/tests/test_scene_rendering/test_play_logic.py@@ -101,3 +101,19 @@ def test_t_values_save_last_frame(using_temp_config):scene.update_to_time = Mock()scene.render()scene.update_to_time.assert_called_once_with(1)+++def test_animate_with_changed_custom_attribute(using_temp_config):+ """Test that animating the change of a custom attribute+ using the animate syntax works correctly.+ """++ class CustomAnimateScene(Scene):+ def construct(self):+ vt = ValueTracker(0)+ vt.custom_attribute = "hello"+ self.play(vt.animate.set_value(42).set(custom_attribute="world"))+ assert vt.get_value() == 42+ assert vt.custom_attribute == "world"++ CustomAnimateScene().render()