Skip to content

Commit

Permalink
Add more docstrings in manim.utils.updaters
Browse files Browse the repository at this point in the history
  • Loading branch information
chopan050 committed Jun 16, 2024
1 parent 8165502 commit 33737d6
Showing 1 changed file with 70 additions and 5 deletions.
75 changes: 70 additions & 5 deletions manim/utils/updaters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import inspect
from collections.abc import Callable
from typing import TYPE_CHECKING, Union
from typing import TYPE_CHECKING, TypeVar, Union

if TYPE_CHECKING:
from typing_extensions import TypeAlias

from manim.mobject.mobject import Mobject
from manim.mobject.opengl.opengl_mobject import OpenGLMobject
from manim.opengl.shader import Object3D


Expand All @@ -24,8 +25,10 @@
]


MobjectTimeBasedUpdater: TypeAlias = Callable[["Mobject", float], "Mobject"]
MobjectNonTimeBasedUpdater: TypeAlias = Callable[["Mobject"], "Mobject"]
M = TypeVar("M", bound=Union["Mobject", "OpenGLMobject"])

MobjectTimeBasedUpdater: TypeAlias = Callable[[M, float], M]
MobjectNonTimeBasedUpdater: TypeAlias = Callable[[M], M]
MobjectUpdater: TypeAlias = Union[MobjectNonTimeBasedUpdater, MobjectTimeBasedUpdater]

MeshTimeBasedUpdater: TypeAlias = Callable[["Object3D", float], "Object3D"]
Expand All @@ -36,6 +39,33 @@


class AbstractUpdaterWrapper:
"""Base class for :class:`MobjectUpdaterWrapper` and
:class:`MeshUpdaterWrapper`. See :class:`MobjectUpdaterWrapper` for more
information.
Parameters
----------
updater
An updater function, whose first parameter is either a :class:`Mobject`
or an :class:`Object3D` (parent of :class:`Mesh`) and
might optionally have a second parameter which should be a ``float``
representing a time change ``dt``. This function should return the same
object in the 1st parameter after applying a change on it.
Attributes
----------
updater
The same updater function passed as a parameter.
is_time_based
Whether :attr:`updater` is a time-based updater or not.
Raises
------
ValueError
If an updater is passed with 0 or more than 2 parameters with no
default values.
"""

__slots__ = ["updater", "is_time_based"]

def __init__(self, updater: MobjectUpdater | MeshUpdater):
Expand Down Expand Up @@ -130,12 +160,20 @@ class MobjectUpdaterWrapper(AbstractUpdaterWrapper):
Do **NOT** name the 1st parameter ``cls`` if the function is not a
class method.
Attributes
Parameters
----------
updater
An updater function, whose first parameter is a :class:`Mobject` and
might optionally have a second parameter which should be a ``float``
representing a time change ``dt``.
representing a time change ``dt``. This function should return the same
:class:`Mobject` after applying a change on it.
Attributes
----------
updater
The same updater function passed as a parameter.
is_time_based
Whether :attr:`updater` is a time-based updater or not.
Raises
------
Expand All @@ -149,5 +187,32 @@ def __init__(self, updater: MobjectUpdater):


class MeshUpdaterWrapper(AbstractUpdaterWrapper):
"""Similar to :class:`MobjectUpdaterWrapper`, but for :class:`Object3D`,
parent of :class:`Mesh`. See the docs for :class:`MobjectUpdaterWrapper`
for more information.
Parameters
----------
updater
An updater function, whose first parameter is an :class:`Object3D`
(parent of :class:`Mesh`) and might optionally have a second parameter
which should be a ``float`` representing a time change ``dt``. This
function should return the same :class:`Object3D` after applying a
change on it.
Attributes
----------
updater
The same updater function passed as a parameter.
is_time_based
Whether :attr:`updater` is a time-based updater or not.
Raises
------
ValueError
If an updater is passed with 0 or more than 2 parameters with no
default values.
"""

def __init__(self, updater: MeshUpdater):
super().__init__(updater)

0 comments on commit 33737d6

Please sign in to comment.