Skip to content

Commit 6c9505b

Browse files
authored
fix(lib): use optional instead of mutable defaults (#291)
* fix(lib): use optional instead of mutable defaults * fix: add missing check for none
1 parent 7b3a5c4 commit 6c9505b

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

manim_slides/slide/animation.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
__all__ = ["Wipe", "Zoom"]
1313

14-
from typing import Any, Mapping, Sequence
14+
from typing import Any, Mapping, Optional, Sequence
1515

1616
import numpy as np
1717

@@ -62,20 +62,28 @@ def construct(self):
6262

6363
def __init__(
6464
self,
65-
current: Sequence[Mobject] = [],
66-
future: Sequence[Mobject] = [],
65+
current: Optional[Sequence[Mobject]] = None,
66+
future: Optional[Sequence[Mobject]] = None,
6767
shift: np.ndarray = LEFT,
68-
fade_in_kwargs: Mapping[str, Any] = {},
69-
fade_out_kwargs: Mapping[str, Any] = {},
68+
fade_in_kwargs: Optional[Mapping[str, Any]] = None,
69+
fade_out_kwargs: Optional[Mapping[str, Any]] = None,
7070
**kwargs: Any,
7171
):
7272
animations = []
7373

74-
for mobject in future:
75-
animations.append(FadeIn(mobject, shift=shift, **fade_in_kwargs))
74+
if future:
75+
if fade_in_kwargs is None:
76+
fade_in_kwargs = {}
7677

77-
for mobject in current:
78-
animations.append(FadeOut(mobject, shift=shift, **fade_out_kwargs))
78+
for mobject in future:
79+
animations.append(FadeIn(mobject, shift=shift, **fade_in_kwargs))
80+
81+
if current:
82+
if fade_out_kwargs is None:
83+
fade_out_kwargs = {}
84+
85+
for mobject in current:
86+
animations.append(FadeOut(mobject, shift=shift, **fade_out_kwargs))
7987

8088
super().__init__(*animations, **kwargs)
8189

@@ -118,12 +126,12 @@ def construct(self):
118126

119127
def __init__(
120128
self,
121-
current: Sequence[Mobject] = [],
122-
future: Sequence[Mobject] = [],
129+
current: Optional[Sequence[Mobject]] = None,
130+
future: Optional[Sequence[Mobject]] = None,
123131
scale: float = 4.0,
124132
out: bool = False,
125-
fade_in_kwargs: Mapping[str, Any] = {},
126-
fade_out_kwargs: Mapping[str, Any] = {},
133+
fade_in_kwargs: Optional[Mapping[str, Any]] = None,
134+
fade_out_kwargs: Optional[Mapping[str, Any]] = None,
127135
**kwargs: Any,
128136
) -> None:
129137
scale_in = 1.0 / scale
@@ -134,10 +142,18 @@ def __init__(
134142

135143
animations = []
136144

137-
for mobject in future:
138-
animations.append(FadeIn(mobject, scale=scale_in, **fade_in_kwargs))
145+
if future:
146+
if fade_in_kwargs is None:
147+
fade_in_kwargs = {}
148+
149+
for mobject in future:
150+
animations.append(FadeIn(mobject, scale=scale_in, **fade_in_kwargs))
151+
152+
if current:
153+
if fade_out_kwargs is None:
154+
fade_out_kwargs = {}
139155

140-
for mobject in current:
141-
animations.append(FadeOut(mobject, scale=scale_out, **fade_out_kwargs))
156+
for mobject in current:
157+
animations.append(FadeOut(mobject, scale=scale_out, **fade_out_kwargs))
142158

143159
super().__init__(*animations, **kwargs)

0 commit comments

Comments
 (0)