Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typing of Animation #3568

Merged
merged 5 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions manim/animation/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


from copy import deepcopy
from typing import TYPE_CHECKING, Callable, Iterable, Sequence
from typing import TYPE_CHECKING, Callable, Iterable, Sequence, cast

if TYPE_CHECKING:
from manim.scene.scene import Scene
Expand Down Expand Up @@ -122,7 +122,7 @@ def __new__(
f"{type(mobject).__name__} mobjects. use_override = False can "
f" be used as keyword argument to prevent animation overriding.",
)
return anim
return cast(cls, anim)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return cast(cls, anim)
return anim

The suggestion:

With typing_extensions.Self imported:

    def __new__(
        cls,
        mobject: Mobject | None = None,
        *args: Any,
        use_override: bool = True,
        **kwargs: Any,
    ) -> Self:

return super().__new__(cls)

def __init__(
Expand Down
4 changes: 3 additions & 1 deletion manim/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,9 @@
# Due to current limitations
# (see https://github.com/python/mypy/issues/14656 / 8263),
# we don't specify the first argument type (Mobject).
FunctionOverride: TypeAlias = Callable[..., None]
# Nor are we able to specify the return type (Animation) since we cannot import
# that here.
FunctionOverride: TypeAlias = Callable
"""Function type returning an :class:`~.Animation` for the specified
:class:`~.Mobject`.
"""
Expand Down
Loading