Skip to content

Improve FadeIn and FadeOut classes with error handling and type safety #4308

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

GiorgosTsak
Copy link

Improved the FadeIn and FadeOut animation classes by adding error handling and type safety. Specifically, it introduces checks for the validity of mobjects, shift, target_position, and scale parameters, raising exceptions when incorrect types or values are provided. The creation of faded mobject copies is now validated to prevent unexpected runtime errors. Additionally, the scene cleanup process includes a try/except block around interpolate(0) to handle potential failures gracefully.

@@ -20,10 +20,9 @@
]

import numpy as np
from typing_extensions import Any
from typing import Any, Union

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'Union' is not used.
Copy link

@OliverStrait OliverStrait left a comment

Choose a reason for hiding this comment

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

Careless errors and some checks is already done in root-class.

try:
self.interpolate(0)
except Exception as e:
raise RuntimeError(f"Error during cleanup interpolation: {e}")

Choose a reason for hiding this comment

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

Does this really add value?
Anyway, this is correct way to write these kinds: raise RuntimeError(f"Error during cleanup interpolation") from e

@@ -143,7 +169,7 @@ def create_starting_mobject(self) -> Mobject:


class FadeOut(_Fade):
r"""Fade out :class:`~.Mobject` s.
r"""Fade out :class:`~.Mobject` s.

Choose a reason for hiding this comment

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

Indentation error

return faded_mobject


class FadeIn(_Fade):
r"""Fade in :class:`~.Mobject` s.
r"""Fade in :class:`~.Mobject` s.

Choose a reason for hiding this comment

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

Indentation error

super().__init__(mobject, **kwargs)

def _create_faded_mobject(self, fadeIn: bool) -> Mobject:
"""Create a faded, shifted and scaled copy of the mobject.
"""Create a faded, shifted and scaled copy of the mobject.

Choose a reason for hiding this comment

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

Indentation error


faded_mobject = self.mobject.copy() # type: ignore[assignment]

if not isinstance(faded_mobject, Mobject):

Choose a reason for hiding this comment

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

This check is redudant because root-Class does not allow content to be anything else than Mobject.
And if copy cannot return same type, then it is not problem in here.

@github-project-automation github-project-automation bot moved this from 🆕 New to 👀 In review in Dev Board Jun 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

2 participants