mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Enhance Autocompletion for mobject.animate.
to Display Mobject
Methods (#2342)
* Improve autocompletion for mobject.animate to show Mobject methods - Added type hint `-> _AnimationBuilder | Self` to `Mobject.animate`, enabling autocompletion for `Mobject` methods after `mobject.animate`. - Prioritized `typing_extensions.Self` over `typing.Self` in imports, so autocompletion of `Mobject` methods also works in Python < 3.11. * Support `mobject.animate.` autocompletion in IPython * Add docstring to `__dir__` and add return type hint * improve docsting `__dir__` _AnimationBuilder
This commit is contained in:
parent
7787730743
commit
6fb1845f4a
2 changed files with 15 additions and 3 deletions
|
@ -160,7 +160,7 @@ class Mobject(object):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def animate(self) -> _AnimationBuilder:
|
def animate(self) -> _AnimationBuilder | Self:
|
||||||
"""
|
"""
|
||||||
Methods called with Mobject.animate.method() can be passed
|
Methods called with Mobject.animate.method() can be passed
|
||||||
into a Scene.play call, as if you were calling
|
into a Scene.play call, as if you were calling
|
||||||
|
@ -2256,6 +2256,18 @@ class _AnimationBuilder:
|
||||||
def __call__(self, **kwargs):
|
def __call__(self, **kwargs):
|
||||||
return self.set_anim_args(**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):
|
def set_anim_args(self, **kwargs):
|
||||||
'''
|
'''
|
||||||
You can change the args of :class:`~manimlib.animation.transform.Transform`, such as
|
You can change the args of :class:`~manimlib.animation.transform.Transform`, such as
|
||||||
|
|
|
@ -7,9 +7,9 @@ if TYPE_CHECKING:
|
||||||
import re
|
import re
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from typing import Self
|
|
||||||
except ImportError:
|
|
||||||
from typing_extensions import Self
|
from typing_extensions import Self
|
||||||
|
except ImportError:
|
||||||
|
from typing import Self
|
||||||
|
|
||||||
# Abbreviations for a common types
|
# Abbreviations for a common types
|
||||||
ManimColor = Union[str, Color, None]
|
ManimColor = Union[str, Color, None]
|
||||||
|
|
Loading…
Add table
Reference in a new issue