Add type annotations to 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.
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.
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.
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.
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.
| reference_colors: Sequence[ParsableManimColor], | ||
| length_of_output: int, | ||
| ) -> list[ManimColor] | ManimColor: | ||
| ) -> list[ManimColor]: |
| """ | ||
| if length_of_output == 0: | ||
| return ManimColor(reference_colors[0]) | ||
| return [ManimColor(reference_colors[0])] |
| animation_overrides: dict[ | ||
| type[Animation], | ||
| FunctionOverride, | ||
| ] = {} |
There was a problem hiding this comment.
By specifying the type of animation_overrides here, a lot of type errors like "type[Mobject]" has no attribute "animation_overrides" are removed.
|
One of the main contributions in this PR is that when accessing elements in a This is achieved by adding/modifying these methods including type annotations to the And these to the |
… code for the remaning 10 errors
…in elements during runtime and not only during type checking
…future cleanup task
Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com>
for more information, see https://pre-commit.ci
| margin: float, | ||
| only_mobjects_in_frame: bool, | ||
| animate: Literal[False], | ||
| ) -> Mobject: ... |
Check notice
Code scanning / CodeQL
Statement has no effect
| margin: float, | ||
| only_mobjects_in_frame: bool, | ||
| animate: Literal[True], | ||
| ) -> _AnimationBuilder: ... |
Check notice
Code scanning / CodeQL
Statement has no effect
|
@chopan050 Thanks for all the comments, even the minor nitpicks! I feel they help me improving the PR. |
|
The I have attempted to solve the issue through implementing a |
# Conflicts: # manim/mobject/matrix.py # manim/mobject/mobject.py # manim/mobject/types/vectorized_mobject.py
for more information, see https://pre-commit.ci
Replace Self with _UpdateBuilder
Overview: What does this pull request change?
This PR add type annotations to
mobject.py.Issue #3375.
Reviewer Checklist