Fix unintended kwargs propagation in LaggedStartMap (#4613)

* Fix unintended kwargs propagation in LaggedStartMap

Ensure  intended for  are not forwarded to the superclass, and make  explicit.

* add test for keyword propagation in LaggedStartMap

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update test_composition.py

update the test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update test_composition.py

add there_and_back

---------

Co-authored-by: Benjamin Hackl <mail@behackl.dev>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Irvanal Haq 2026-02-27 13:14:28 +07:00 committed by GitHub
commit 6f825e8513
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 3 deletions

View file

@ -353,7 +353,7 @@ class LaggedStartMap(LaggedStart):
Parameters
----------
AnimationClass
animation_class
:class:`~.Animation` to apply to mobject.
mobject
:class:`~.Mobject` whose submobjects the animation, and optionally the function,
@ -362,6 +362,17 @@ class LaggedStartMap(LaggedStart):
Function which will be applied to :class:`~.Mobject`.
run_time
The duration of the animation in seconds.
lag_ratio
Defines the delay after which the animation is applied to submobjects. A lag_ratio of
``n.nn`` means the next animation will play when ``nnn%`` of the current animation has played.
Defaults to 0.05, meaning that the next animation will begin when 5% of the current
animation has played.
This does not influence the total runtime of the animation. Instead the runtime
of individual animations is adjusted so that the complete animation has the defined
run time.
kwargs
Further keyword arguments that are passed to `animation_class`.
Examples
--------
@ -392,6 +403,7 @@ class LaggedStartMap(LaggedStart):
mobject: Mobject,
arg_creator: Callable[[Mobject], Iterable[Any]] | None = None,
run_time: float = 2,
lag_ratio: float = DEFAULT_LAGGED_START_LAG_RATIO,
**kwargs: Any,
):
if arg_creator is None:
@ -406,4 +418,4 @@ class LaggedStartMap(LaggedStart):
if "lag_ratio" in anim_kwargs:
anim_kwargs.pop("lag_ratio")
animations = [animation_class(*args, **anim_kwargs) for args in args_list]
super().__init__(*animations, run_time=run_time, **kwargs)
super().__init__(*animations, run_time=run_time, lag_ratio=lag_ratio)

View file

@ -5,14 +5,16 @@ from unittest.mock import MagicMock
import pytest
from manim.animation.animation import Animation, Wait
from manim.animation.composition import AnimationGroup, Succession
from manim.animation.composition import AnimationGroup, LaggedStartMap, Succession
from manim.animation.creation import Create, Write
from manim.animation.fading import FadeIn, FadeOut
from manim.constants import DOWN, UP
from manim.mobject.geometry.arc import Circle
from manim.mobject.geometry.line import Line
from manim.mobject.geometry.polygram import RegularPolygon, Square
from manim.mobject.types.vectorized_mobject import VGroup
from manim.scene.scene import Scene
from manim.utils.rate_functions import linear, there_and_back
def test_succession_timing():
@ -189,6 +191,23 @@ def test_animationgroup_calls_finish():
assert circ_animation.finished
def test_laggedstartmap_only_passes_kwargs_to_subanimations():
mobject = VGroup(Square(), Circle())
animation = LaggedStartMap(
FadeIn,
mobject,
rate_func=there_and_back,
lag_ratio=0.3,
)
assert animation.rate_func is linear
assert animation.lag_ratio == 0.3
assert all(
subanimation.rate_func is there_and_back
for subanimation in animation.animations
)
def test_empty_animation_group_fails():
with pytest.raises(ValueError, match="Please add at least one subanimation."):
AnimationGroup().begin()