A community-maintained Python framework for creating mathematical animations.
some type fixes address review comments
Syrus Darkeb75103e388b
diff --git a/manim/_config/utils.py b/manim/_config/utils.pyindex 47ced109f..b47054e78 100644--- a/manim/_config/utils.py+++ b/manim/_config/utils.py@@ -113,7 +113,7 @@ def make_config_parser(custom_file: str = None) -> configparser.ConfigParser:return parser-def _determine_quality(args) -> str: # what is args type??+def _determine_quality(args: argparse.Namespace) -> str:old_qualities = {"k": "fourk_quality","e": "high_quality",@@ -312,7 +312,7 @@ class ManimConfig(MutableMapping):def __getitem__(self, key) -> typing.Any:return getattr(self, key)- def __setitem__(self, key, val) -> None: # what is the type here?+ def __setitem__(self, key: str, val: typing.Any) -> None:getattr(ManimConfig, key).fset(self, val) # fset is the property's setterdef update(self, obj: typing.Union["ManimConfig", dict]) -> None:@@ -357,10 +357,10 @@ class ManimConfig(MutableMapping):self[k] = v# don't allow to delete anything- def __delitem__(self, key): # typing?+ def __delitem__(self, key: str):raise AttributeError("'ManimConfig' object does not support item deletion")- def __delattr__(self, key): # typing?+ def __delattr__(self, key: str):raise AttributeError("'ManimConfig' object does not support item deletion")# copy functions@@ -387,7 +387,7 @@ class ManimConfig(MutableMapping):"""See ManimConfig.copy()."""return copy.deepcopy(self)- def __deepcopy__(self, memo) -> "ManimConfig": # typing?+ def __deepcopy__(self, memo: typing.Dict[str, typing.Any]) -> "ManimConfig":"""See ManimConfig.copy()."""c = ManimConfig()# Deepcopying the underlying dict is enough because all properties@@ -397,9 +397,7 @@ class ManimConfig(MutableMapping):return c# helper type-checking methods- def _set_from_list(- self, key: str, val: typing.Union[str, int], values: list- ) -> None: # correct?+ def _set_from_list(self, key: str, val: typing.Any, values: list) -> None:"""Set ``key`` to ``val`` if ``val`` is contained in ``values``."""if val in values:self._d[key] = val@@ -413,7 +411,7 @@ class ManimConfig(MutableMapping):else:raise ValueError(f"{key} must be boolean")- def _set_str(self, key: typing.Union[str, int], val: typing.Any) -> None:+ def _set_str(self, key: str, val: typing.Any) -> None:"""Set ``key`` to ``val`` if ``val`` is a string."""if isinstance(val, str):self._d[key] = val@@ -422,18 +420,14 @@ class ManimConfig(MutableMapping):else:raise ValueError(f"{key} must be str or falsy value")- def _set_between(- self, key: typing.Union[str, int], val: int, lo: int, hi: int- ) -> None:+ def _set_between(self, key: str, val: float, lo: float, hi: float) -> None:"""Set ``key`` to ``val`` if lo <= val <= hi."""if lo <= val <= hi:self._d[key] = valelse:raise ValueError(f"{key} must be {lo} <= {key} <= {hi}")- def _set_pos_number(- self, key: typing.Union[str, int], val: int, allow_inf: bool- ) -> None:+ def _set_pos_number(self, key: str, val: int, allow_inf: bool) -> None:"""Set ``key`` to ``val`` if ``val`` is a positive integer."""if isinstance(val, int) and val > -1:self._d[key] = val@@ -1192,7 +1186,7 @@ class ManimConfig(MutableMapping):return Path(path) if path else None- def _set_dir(self, key: typing.Union[str, int], val: typing.Union[str, Path]):+ def _set_dir(self, key: str, val: typing.Union[str, Path]):if isinstance(val, Path):self._d.__setitem__(key, str(val))else:diff --git a/manim/animation/animation.py b/manim/animation/animation.pyindex 228d8e2e7..d6902c477 100644--- a/manim/animation/animation.py+++ b/manim/animation/animation.py@@ -17,7 +17,7 @@ from ..mobject.mobject import Mobjectfrom ..utils.rate_functions import smoothDEFAULT_ANIMATION_RUN_TIME: float = 1.0-DEFAULT_ANIMATION_LAG_RATIO: int = 0+DEFAULT_ANIMATION_LAG_RATIO: float = 0class Animation:diff --git a/manim/animation/creation.py b/manim/animation/creation.pyindex 9adf23da8..fa3d70281 100644--- a/manim/animation/creation.py+++ b/manim/animation/creation.py@@ -143,7 +143,7 @@ class ShowCreation(ShowPartial):"""- def __init__(self, mobject: VMobject, lag_ratio: float = 1, **kwargs) -> None:+ def __init__(self, mobject: VMobject, lag_ratio: float = 1.0, **kwargs) -> None:super().__init__(mobject, lag_ratio=lag_ratio, **kwargs)def _get_bounds(self, alpha: float) -> typing.Tuple[int, float]:diff --git a/manim/animation/growing.py b/manim/animation/growing.pyindex 421d1e3b6..771c5f87e 100644--- a/manim/animation/growing.py+++ b/manim/animation/growing.py@@ -59,7 +59,5 @@ class GrowArrow(GrowFromPoint):class SpinInFromNothing(GrowFromCenter):- def __init__(- self, mobject: "Mobject", path_arc: typing.Optional[float] = PI, **kwargs- ) -> None:+ def __init__(self, mobject: "Mobject", path_arc: float = PI, **kwargs) -> None:super().__init__(mobject, path_arc=path_arc, **kwargs)diff --git a/manim/animation/indication.py b/manim/animation/indication.pyindex ace4ca2d5..49a7dbd5c 100644--- a/manim/animation/indication.py+++ b/manim/animation/indication.py@@ -100,12 +100,12 @@ class Flash(AnimationGroup):def __init__(self,point: np.ndarray,- line_length: typing.Optional[float] = 0.2,- num_lines: typing.Optional[int] = 12,- flash_radius: typing.Optional[float] = 0.3,- line_stroke_width: typing.Optional[int] = 3,- color: typing.Optional[str] = YELLOW,- run_time: typing.Optional[int] = 1,+ line_length: float = 0.2,+ num_lines: int = 12,+ flash_radius: float = 0.3,+ line_stroke_width: int = 3,+ color: str = YELLOW,+ run_time: int = 1,**kwargs) -> None:self.point = pointdiff --git a/manim/animation/movement.py b/manim/animation/movement.pyindex 2a784b408..76581928c 100644--- a/manim/animation/movement.py+++ b/manim/animation/movement.py@@ -27,7 +27,7 @@ class Homotopy(Animation):[float, float, float, float], typing.Tuple[float, float, float]],mobject: "Mobject",- run_time: typing.Optional[float] = 3,+ run_time: float = 3,apply_function_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = None,**kwargs) -> None:@@ -86,12 +86,10 @@ class PhaseFlow(Animation):self,function: typing.Callable[[np.ndarray], np.ndarray],mobject: "Mobject",- virtual_time: typing.Optional[float] = 1,- suspend_mobject_updating: typing.Optional[bool] = False,- rate_func: typing.Optional[- typing.Callable[- [typing.Union[np.ndarray, float]], typing.Union[np.ndarray, float]- ]+ virtual_time: float = 1,+ suspend_mobject_updating: bool = False,+ rate_func: typing.Callable[+ [typing.Union[np.ndarray, float]], typing.Union[np.ndarray, float]] = linear,**kwargs) -> None:diff --git a/manim/animation/rotation.py b/manim/animation/rotation.pyindex 78b3baee5..a0ab8789e 100644--- a/manim/animation/rotation.py+++ b/manim/animation/rotation.py@@ -19,11 +19,11 @@ class Rotating(Animation):def __init__(self,mobject: "Mobject",- axis: typing.Optional[np.ndarray] = OUT,- radians: typing.Optional[np.ndarray] = TAU,+ axis: np.ndarray = OUT,+ radians: np.ndarray = TAU,about_point: typing.Optional[np.ndarray] = None,about_edge: typing.Optional[np.ndarray] = None,- run_time: typing.Optional[float] = 5,+ run_time: float = 5,rate_func: typing.Callable[[typing.Union[np.ndarray, float]], typing.Union[np.ndarray, float]] = linear,@@ -49,8 +49,8 @@ class Rotate(Transform):def __init__(self,mobject: "Mobject",- angle: typing.Optional[np.ndarray] = PI,- axis: typing.Optional[np.ndarray] = OUT,+ angle: np.ndarray = PI,+ axis: np.ndarray = OUT,about_point: typing.Optional[np.ndarray] = None,about_edge: typing.Optional[np.ndarray] = None,**kwargsdiff --git a/manim/animation/transform.py b/manim/animation/transform.pyindex e389635bb..263d4a0ce 100644--- a/manim/animation/transform.py+++ b/manim/animation/transform.py@@ -212,7 +212,7 @@ class ApplyMethod(Transform):)assert isinstance(method.__self__, Mobject)- def create_target(self): # what is returned?+ def create_target(self) -> Mobject:method = self.method# Make sure it's a list so that args.pop() worksargs = list(self.method_args)diff --git a/manim/utils/rate_functions.py b/manim/utils/rate_functions.pyindex 6361edb43..21142ba44 100644--- a/manim/utils/rate_functions.py+++ b/manim/utils/rate_functions.py@@ -78,7 +78,7 @@ def linear(t: typing.Union[np.ndarray, float]) -> typing.Union[np.ndarray, floatreturn t-def smooth(t: float, inflection: typing.Optional[float] = 10.0) -> np.ndarray:+def smooth(t: float, inflection: float = 10.0) -> np.ndarray:error = sigmoid(-inflection / 2)return np.clip((sigmoid(inflection * (t - 0.5)) - error) / (1 - 2 * error),@@ -106,7 +106,7 @@ def double_smooth(t: float) -> np.ndarray:return 0.5 * (1 + smooth(2 * t - 1))-def there_and_back(t: float, inflection: typing.Optional[float] = 10.0) -> np.ndarray:+def there_and_back(t: float, inflection: float = 10.0) -> np.ndarray:new_t = 2 * t if t < 0.5 else 2 * (1 - t)return smooth(new_t, inflection)