-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add type annotations to cairo_renderer.py
#4393
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
@@ -186,7 +186,7 @@ def __init__( | |||
self.moving_mobjects: list[Mobject] = [] | |||
self.static_mobjects: list[Mobject] = [] | |||
self.time_progression: tqdm[float] | None = None | |||
self.duration: float | None = None | |||
self.duration: float = 0.0 |
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.
As far as I can tell setting self.duration = 0.0
, will not cause any problems, but it avoids having to deal with it being None
when calculating number of static frames or self.time
.
@@ -226,7 +233,7 @@ def save_static_frame_data( | |||
|
|||
Returns | |||
------- | |||
typing.Iterable[Mobject] | |||
Iterable[Mobject] | |||
The static image computed. | |||
""" | |||
self.static_image = None |
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.
For consistency with other methods and variables self.static_image
should ideally be renamed to self.static_frame
, but that can be done in another PR.
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.
Thanks for the type annotations, especially those for manim.utils.hashing
! That's a pretty difficult module to type properly.
I left some change requests:
@@ -285,8 +286,11 @@ def _iter_check_dict(dct): | |||
return _iter_check_list(iterable) |
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.
Can you please replace
if isinstance(iterable, (list, tuple)):
with
if isinstance(iterable, Sequence):
?
Lists and tuples pass that check.
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.
I will move this to a separate PR, since it is not specifically related to cairo_renderer.py
and causes some tests to fail.
Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com>
Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com>
Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com>
@@ -233,22 +234,28 @@ | |||
# Serialize it with only the type of the object. You can change this to whatever string when debugging the serialization process. | |||
return str(type(obj)) | |||
|
|||
def _cleaned_iterable(self, iterable: Iterable[Any]): | |||
@overload | |||
def _cleaned_iterable(self, iterable: Sequence[Any]) -> list[Any]: ... |
Check notice
Code scanning / CodeQL
Statement has no effect Note
def _cleaned_iterable(self, iterable: Sequence[Any]) -> list[Any]: ... | ||
|
||
@overload | ||
def _cleaned_iterable(self, iterable: dict[Any, Any]) -> dict[Any, Any]: ... |
Check notice
Code scanning / CodeQL
Statement has no effect Note
Overview: What does this pull request change?
More work towards completing #3375.
Motivation and Explanation: Why and how do your changes improve the library?
This PR includes some type annotations to
utils/hashing.py
to complete typing forcairo_renderer.py
. Typing forutils/hashing.py
should be completed in another PR.Reviewer Checklist