Skip to content
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

Type annotation work in manim/mobject/geometry/ #3961

Merged
merged 44 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
35597d5
Removed type annotation errors
henrikmidtiby Oct 17, 2024
cd73909
Removed type annotation errors
henrikmidtiby Oct 17, 2024
1ba82f7
Removed typing errors in mobject/geometry/arc.py
henrikmidtiby Oct 17, 2024
3b38bba
Removed typing errors in mobject/geometry/shape_matchers.py
henrikmidtiby Oct 18, 2024
b6f8e38
Added type annotations fo mobject/types/image_mobject.py and a few ot…
henrikmidtiby Oct 18, 2024
5bf79dc
Avoid overwriting the invert method of the superclass
henrikmidtiby Oct 18, 2024
612068d
Adding type annotations to types/point_cloud_mobject.py
henrikmidtiby Oct 18, 2024
774c136
Fixing issues revealed by type annotations in types/point_cloud_mobje…
henrikmidtiby Oct 18, 2024
be3938d
Fix issue in the CI step related to the Camera class.
henrikmidtiby Oct 18, 2024
5be34e3
Removed type errors by replacing Point3D with InternalPoint3D
henrikmidtiby Oct 18, 2024
bbfb247
Adding type annotations to geometry/line.py
henrikmidtiby Oct 18, 2024
d294e6f
Fix issues identified by type annotations.
henrikmidtiby Oct 18, 2024
00a0b1f
Work on type annotations in geometry/polygram.py
henrikmidtiby Oct 18, 2024
257c023
Ignore type errors related to super and sub class in line.py and shap…
henrikmidtiby Oct 19, 2024
6b88833
Remove return value from the internal method _account_for_buff
henrikmidtiby Oct 19, 2024
16716a4
Dealing with some issues and ignoring others identified by type checking
henrikmidtiby Oct 19, 2024
efe49b7
Ignored a number of type issues related to float and floating[Any].
henrikmidtiby Oct 20, 2024
68a3d66
Help mypy to determine types.
henrikmidtiby Oct 20, 2024
80226e2
Fix issues identified by mypy
henrikmidtiby Oct 20, 2024
0018f8d
Change example in docs for _convert_2d_to_3d_array
henrikmidtiby Oct 21, 2024
56d2a94
Change example in docs for _convert_2d_to_3d_array to make the doctes…
henrikmidtiby Oct 21, 2024
66d2cea
More work on addressing typing issues.
henrikmidtiby Oct 21, 2024
33da68d
Reverting two changes that triggers an error in the automatic testing.
henrikmidtiby Oct 21, 2024
e498903
Further work on type hinting.
henrikmidtiby Oct 21, 2024
e18a644
Added comment to why these mypy errors can be ignored
henrikmidtiby Oct 22, 2024
80ae857
Avoid forwarding positional arguments from Arrow to Line in the const…
henrikmidtiby Oct 22, 2024
d477c9a
Activate mypy check of mobject.geometry.*
henrikmidtiby Oct 22, 2024
a14b99a
Revert "Avoid forwarding positional arguments from Arrow to Line in t…
henrikmidtiby Oct 22, 2024
07bbe3f
Removed several type ignore statements and addressed comments from Ja…
henrikmidtiby Oct 22, 2024
46bbcba
Revert "Activate mypy check of mobject.geometry.*"
henrikmidtiby Oct 22, 2024
61a9168
Revert "Removed several type ignore statements and addressed comments…
henrikmidtiby Oct 22, 2024
50169c2
Update manim/mobject/geometry/arc.py
henrikmidtiby Oct 25, 2024
daa6a08
Remove redundant type annotations.
henrikmidtiby Oct 25, 2024
7647209
Change np.array to np.asarray
henrikmidtiby Oct 25, 2024
581c72a
Avoid type annotations in comments.
henrikmidtiby Oct 25, 2024
ed422ce
Change from np.array to np.asarray
henrikmidtiby Oct 25, 2024
601072d
Switch to StrPath for typing in two locations.
henrikmidtiby Oct 25, 2024
ecd9357
Change the type annotation Any to something more specific.
henrikmidtiby Oct 25, 2024
3e30555
Change InternalPoint3D to Point3D for an argument to the Polygram con…
henrikmidtiby Oct 25, 2024
9a92bf5
Remove unneccessary noqa
JasonGrace2282 Oct 27, 2024
5bfc25e
Merge branch 'main' of https://github.com/ManimCommunity/manim into t…
JasonGrace2282 Oct 27, 2024
53ba462
enable mypy type-checking on manim.mobject.geometry.*
JasonGrace2282 Oct 27, 2024
d288979
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 27, 2024
01e566a
fix mypy ci
JasonGrace2282 Oct 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 81 additions & 58 deletions manim/mobject/geometry/arc.py

Large diffs are not rendered by default.

27 changes: 15 additions & 12 deletions manim/mobject/geometry/boolean_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
from manim.mobject.types.vectorized_mobject import VMobject

if TYPE_CHECKING:
from manim.typing import Point2D_Array, Point3D_Array
from typing import Any

from manim.typing import InternalPoint3D_Array, Point2D_Array

from ...constants import RendererType

Expand All @@ -30,7 +32,7 @@ def _convert_2d_to_3d_array(
self,
points: Point2D_Array,
z_dim: float = 0.0,
) -> Point3D_Array:
) -> InternalPoint3D_Array:
"""Converts an iterable with coordinates in 2D to 3D by adding
:attr:`z_dim` as the Z coordinate.

Expand All @@ -51,13 +53,14 @@ def _convert_2d_to_3d_array(
>>> a = _BooleanOps()
>>> p = [(1, 2), (3, 4)]
>>> a._convert_2d_to_3d_array(p)
[array([1., 2., 0.]), array([3., 4., 0.])]
array([[1., 2., 0.],
[3., 4., 0.]])
"""
points = list(points)
for i, point in enumerate(points):
list_of_points = list(points)
for i, point in enumerate(list_of_points):
if len(point) == 2:
points[i] = np.array(list(point) + [z_dim])
return points
list_of_points[i] = np.array(list(point) + [z_dim])
return np.asarray(list_of_points)

def _convert_vmobject_to_skia_path(self, vmobject: VMobject) -> SkiaPath:
"""Converts a :class:`~.VMobject` to SkiaPath. This method only works for
Expand Down Expand Up @@ -95,7 +98,7 @@ def _convert_vmobject_to_skia_path(self, vmobject: VMobject) -> SkiaPath:
if vmobject.consider_points_equals(subpath[0], subpath[-1]):
path.close()
elif config.renderer == RendererType.CAIRO:
subpaths = vmobject.gen_subpaths_from_points_2d(points)
subpaths = vmobject.gen_subpaths_from_points_2d(points) # type: ignore[assignment]
for subpath in subpaths:
quads = vmobject.gen_cubic_bezier_tuples_from_points(subpath)
start = subpath[0]
Expand Down Expand Up @@ -177,7 +180,7 @@ def construct(self):

"""

def __init__(self, *vmobjects: VMobject, **kwargs) -> None:
def __init__(self, *vmobjects: VMobject, **kwargs: Any) -> None:
if len(vmobjects) < 2:
raise ValueError("At least 2 mobjects needed for Union.")
super().__init__(**kwargs)
Expand Down Expand Up @@ -216,7 +219,7 @@ def construct(self):

"""

def __init__(self, subject: VMobject, clip: VMobject, **kwargs) -> None:
def __init__(self, subject: VMobject, clip: VMobject, **kwargs: Any) -> None:
super().__init__(**kwargs)
outpen = SkiaPath()
difference(
Expand Down Expand Up @@ -258,7 +261,7 @@ def construct(self):

"""

def __init__(self, *vmobjects: VMobject, **kwargs) -> None:
def __init__(self, *vmobjects: VMobject, **kwargs: Any) -> None:
if len(vmobjects) < 2:
raise ValueError("At least 2 mobjects needed for Intersection.")

Expand Down Expand Up @@ -311,7 +314,7 @@ def construct(self):

"""

def __init__(self, subject: VMobject, clip: VMobject, **kwargs) -> None:
def __init__(self, subject: VMobject, clip: VMobject, **kwargs: Any) -> None:
super().__init__(**kwargs)
outpen = SkiaPath()
xor(
Expand Down
19 changes: 13 additions & 6 deletions manim/mobject/geometry/labeled.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

__all__ = ["LabeledLine", "LabeledArrow"]

from typing import TYPE_CHECKING

from manim.constants import *
from manim.mobject.geometry.line import Arrow, Line
from manim.mobject.geometry.shape_matchers import (
Expand All @@ -14,6 +16,9 @@
from manim.mobject.text.text_mobject import Text
from manim.utils.color import WHITE, ManimColor, ParsableManimColor

if TYPE_CHECKING:
from typing import Any


class LabeledLine(Line):
"""Constructs a line containing a label box somewhere along its length.
Expand Down Expand Up @@ -67,17 +72,19 @@ def __init__(
font_size: float = DEFAULT_FONT_SIZE,
label_color: ParsableManimColor = WHITE,
label_frame: bool = True,
frame_fill_color: ParsableManimColor = None,
frame_fill_color: ParsableManimColor | None = None,
frame_fill_opacity: float = 1,
*args,
**kwargs,
*args: Any,
**kwargs: Any,
) -> None:
label_color = ManimColor(label_color)
frame_fill_color = ManimColor(frame_fill_color)
if isinstance(label, str):
from manim import MathTex

rendered_label = MathTex(label, color=label_color, font_size=font_size)
rendered_label: Tex | MathTex | Text = MathTex(
label, color=label_color, font_size=font_size
)
else:
rendered_label = label

Expand Down Expand Up @@ -149,7 +156,7 @@ def construct(self):

def __init__(
self,
*args,
**kwargs,
*args: Any,
**kwargs: Any,
) -> None:
super().__init__(*args, **kwargs)
Loading
Loading