-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Typing mobject.py
#4388
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?
Typing mobject.py
#4388
Conversation
# error: Argument "tip" to "add_tip" of "TipableVMobject" has incompatible type "VMobject"; expected "ArrowTip | None" [arg-type] | ||
self.add_tip(tip=old_tips[0]) | ||
if has_start_tip: | ||
# error: Argument "tip" to "add_tip" of "TipableVMobject" has incompatible type "VMobject"; expected "ArrowTip | None" [arg-type] | ||
self.add_tip(tip=old_tips[1], at_start=True) |
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.
These issues can be handled by typing.cast, but I don't think that is the best way to deal with them.
def __getitem__(self, key: int) -> VMobject: | ||
return self.submobjects[key] | ||
|
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 method is used to define the return type when indexing into a VGroup
. If the super class was used, this would return a Mobject
, but in a VGroup
it should be a VMobject
.
temp = self.get_basis_vectors() | ||
i_hat = temp.submobjects[0] | ||
j_hat = temp.submobjects[1] |
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.
Apparently the trick for defining the type of elements in a VGroup to be VMobject's does not work here. Which is the reason for this workaround.
temp = array.get_entries() | ||
x_coord = temp.submobjects[0] | ||
y_coord = temp.submobjects[1] |
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.
Apparently the trick for defining the type of elements in a VGroup to be VMobject's does not work here. Which is the reason for this workaround.
@@ -1409,7 +1409,7 @@ def invert_color(color: ManimColorT) -> ManimColorT: | |||
def color_gradient( | |||
reference_colors: Sequence[ParsableManimColor], | |||
length_of_output: int, | |||
) -> list[ManimColor] | ManimColor: | |||
) -> list[ManimColor]: |
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.
Same change as in PR #4380
@@ -1426,7 +1426,7 @@ def color_gradient( | |||
A :class:`ManimColor` or a list of interpolated :class:`ManimColor`'s. | |||
""" | |||
if length_of_output == 0: | |||
return ManimColor(reference_colors[0]) | |||
return [ManimColor(reference_colors[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.
Same change as in PR #4380.
animation_overrides: dict[ | ||
type[Animation], | ||
FunctionOverride, | ||
] = {} |
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.
By specifying the type of animation_overrides
here, a lot of type errors like "type[Mobject]" has no attribute "animation_overrides"
are removed.
# Conflicts: # manim/mobject/mobject.py
@@ -1227,7 +1244,7 @@ | |||
|
|||
return self | |||
|
|||
def scale(self, scale_factor: float, **kwargs) -> Self: | |||
def scale(self, scale_factor: float, **kwargs: Any) -> Self: |
Check notice
Code scanning / CodeQL
Mismatch between signature and use of an overridden method Note
call
method VMobject.scale
Overridden method signature does not match
call
method VMobject.scale
Overridden method signature does not match
call
method VMobject.scale
Overridden method signature does not match
call
method VMobject.scale
Overridden method signature does not match
call
method VMobject.scale
…in elements during runtime and not only during type checking
Overview: What does this pull request change?
This draft PR is a work in progress to add type annotations to
mobject.py
.I have created the draft PR to request some input on how to handle the remaining mypy issues.
Further Information and Comments
The following mypy errors need to be dealt with
Reviewer Checklist