diff --git a/manimlib/mobject/mobject.py b/manimlib/mobject/mobject.py index 159c8508..cdc4bfc2 100644 --- a/manimlib/mobject/mobject.py +++ b/manimlib/mobject/mobject.py @@ -160,7 +160,7 @@ class Mobject(object): return self @property - def animate(self) -> _AnimationBuilder: + def animate(self) -> _AnimationBuilder | Self: """ Methods called with Mobject.animate.method() can be passed into a Scene.play call, as if you were calling @@ -2256,6 +2256,18 @@ class _AnimationBuilder: def __call__(self, **kwargs): return self.set_anim_args(**kwargs) + def __dir__(self) -> list[str]: + """ + Extend attribute list of _AnimationBuilder object to include mobject attributes + for better autocompletion in the IPython terminal when using interactive mode. + """ + methods = super().__dir__() + mobject_methods = [ + attr for attr in dir(self.mobject) + if not attr.startswith('_') + ] + return sorted(set(methods+mobject_methods)) + def set_anim_args(self, **kwargs): ''' You can change the args of :class:`~manimlib.animation.transform.Transform`, such as diff --git a/manimlib/typing.py b/manimlib/typing.py index c5c55729..9d51a5b5 100644 --- a/manimlib/typing.py +++ b/manimlib/typing.py @@ -7,9 +7,9 @@ if TYPE_CHECKING: import re try: - from typing import Self - except ImportError: from typing_extensions import Self + except ImportError: + from typing import Self # Abbreviations for a common types ManimColor = Union[str, Color, None]