-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
base: main
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
There was a problem hiding this 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}") |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
Improved the
FadeIn
andFadeOut
animation classes by adding error handling and type safety. Specifically, it introduces checks for the validity ofmobjects
,shift
,target_position
, andscale
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 aroundinterpolate(0)
to handle potential failures gracefully.