Skip to content

Commit

Permalink
fix mypy ci
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGrace2282 committed Oct 27, 2024
1 parent d288979 commit 01e566a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 27 deletions.
23 changes: 13 additions & 10 deletions manim/mobject/geometry/arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def construct(self):

import itertools
import warnings
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, cast

import numpy as np
from typing_extensions import Self
Expand Down Expand Up @@ -273,22 +273,22 @@ def get_first_handle(self) -> InternalPoint3D:
# Type inference of extracting an element from a list, is not
# supported by numpy, see this numpy issue
# https://github.com/numpy/numpy/issues/16544
return self.points[1] # type: ignore[no-any-return]
return self.points[1]

def get_last_handle(self) -> InternalPoint3D:
return self.points[-2] # type: ignore[no-any-return]
return self.points[-2]

def get_end(self) -> InternalPoint3D:
if self.has_tip():
return self.tip.get_start() # type: ignore[return-value]
return self.tip.get_start()
else:
return super().get_end() # type: ignore[return-value]
return super().get_end()

def get_start(self) -> InternalPoint3D:
if self.has_start_tip():
return self.start_tip.get_start() # type: ignore[return-value]
return self.start_tip.get_start()
else:
return super().get_start() # type: ignore[return-value]
return super().get_start()

def get_length(self) -> float:
start, end = self.get_start_and_end()
Expand Down Expand Up @@ -427,7 +427,10 @@ def move_arc_center_to(self, point: InternalPoint3D) -> Self:
return self

def stop_angle(self) -> float:
return angle_of_vector(self.points[-1] - self.get_arc_center()) % TAU
return cast(
float,
angle_of_vector(self.points[-1] - self.get_arc_center()) % TAU,
)


class ArcBetweenPoints(Arc):
Expand Down Expand Up @@ -481,7 +484,7 @@ def __init__(
if radius is None:
center = self.get_arc_center(warning=False)
if not self._failed_to_get_center:
temp_radius: float = np.linalg.norm(np.array(start) - np.array(center)) # type: ignore[assignment]
temp_radius: float = np.linalg.norm(np.array(start) - np.array(center))
self.radius = temp_radius
else:
self.radius = np.inf
Expand Down Expand Up @@ -658,7 +661,7 @@ def construct(self):
perpendicular_bisector([np.asarray(p1), np.asarray(p2)]),
perpendicular_bisector([np.asarray(p2), np.asarray(p3)]),
)
radius: float = np.linalg.norm(p1 - center) # type: ignore[assignment]
radius: float = np.linalg.norm(p1 - center)
return Circle(radius=radius, **kwargs).shift(center)


Expand Down
4 changes: 2 additions & 2 deletions manim/mobject/geometry/boolean_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import TYPE_CHECKING

import numpy as np
from pathops import Path as SkiaPath # type: ignore[import-untyped]
from pathops import Path as SkiaPath
from pathops import PathVerb, difference, intersection, union, xor

from manim import config
Expand Down Expand Up @@ -106,7 +106,7 @@ def _convert_vmobject_to_skia_path(self, vmobject: VMobject) -> SkiaPath:
for _p0, p1, p2, p3 in quads:
path.cubicTo(*p1[:2], *p2[:2], *p3[:2])

if vmobject.consider_points_equals_2d(subpath[0], subpath[-1]): # type: ignore[arg-type]
if vmobject.consider_points_equals_2d(subpath[0], subpath[-1]):
path.close()

return path
Expand Down
16 changes: 8 additions & 8 deletions manim/mobject/geometry/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ def _pointify(
if isinstance(mob_or_point, (Mobject, OpenGLMobject)):
mob = mob_or_point
if direction is None:
return mob.get_center() # type: ignore[return-value]
return mob.get_center()
else:
return mob.get_boundary_point(direction) # type: ignore[return-value]
return mob.get_boundary_point(direction)
return np.array(mob_or_point)

def set_path_arc(self, new_value: float) -> None:
Expand All @@ -156,8 +156,8 @@ def set_path_arc(self, new_value: float) -> None:

def put_start_and_end_on(
self,
start: InternalPoint3D, # type: ignore[override]
end: InternalPoint3D, # type: ignore[override]
start: InternalPoint3D,
end: InternalPoint3D,
) -> Self:
"""Sets starts and end coordinates of a line.
Expand Down Expand Up @@ -309,7 +309,7 @@ def get_start(self) -> InternalPoint3D:
array([-1., 0., 0.])
"""
if len(self.submobjects) > 0:
return self.submobjects[0].get_start() # type: ignore[return-value]
return self.submobjects[0].get_start()
else:
return super().get_start()

Expand All @@ -324,7 +324,7 @@ def get_end(self) -> InternalPoint3D:
array([1., 0., 0.])
"""
if len(self.submobjects) > 0:
return self.submobjects[-1].get_end() # type: ignore[return-value]
return self.submobjects[-1].get_end()
else:
return super().get_end()

Expand All @@ -341,7 +341,7 @@ def get_first_handle(self) -> InternalPoint3D:
# Type inference of extracting an element from a list, is not
# supported by numpy, see this numpy issue
# https://github.com/numpy/numpy/issues/16544
return self.submobjects[0].points[1] # type: ignore[no-any-return]
return self.submobjects[0].points[1]

def get_last_handle(self) -> InternalPoint3D:
"""Returns the point of the last handle.
Expand All @@ -356,7 +356,7 @@ def get_last_handle(self) -> InternalPoint3D:
# Type inference of extracting an element from a list, is not
# supported by numpy, see this numpy issue
# https://github.com/numpy/numpy/issues/16544
return self.submobjects[-1].points[-2] # type: ignore[no-any-return]
return self.submobjects[-1].points[-2]


class TangentLine(Line):
Expand Down
6 changes: 3 additions & 3 deletions manim/mobject/geometry/polygram.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(
for vertices in vertex_groups:
# The inferred type for *vertices is Any, but it should be
# InternalPoint3D_Array
first_vertex, *vertices = vertices # type: ignore[assignment]
first_vertex, *vertices = vertices
first_vertex = np.array(first_vertex)

self.start_new_path(first_vertex)
Expand Down Expand Up @@ -322,7 +322,7 @@ def construct(self):
"""

def __init__(self, *vertices: InternalPoint3D, **kwargs: Any) -> None:
super().__init__(vertices, **kwargs) # type: ignore[arg-type]
super().__init__(vertices, **kwargs)


class RegularPolygram(Polygram):
Expand Down Expand Up @@ -413,7 +413,7 @@ def gen_polygon_vertices(start_angle: float | None) -> tuple[list[Any], float]:

vertex_groups.append(group)

super().__init__(*vertex_groups, **kwargs) # type: ignore[arg-type]
super().__init__(*vertex_groups, **kwargs)


class RegularPolygon(RegularPolygram):
Expand Down
2 changes: 1 addition & 1 deletion manim/mobject/geometry/shape_matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def set_style(self, fill_opacity: float, **kwargs: Any) -> Self: # type: ignore
def get_fill_color(self) -> ManimColor:
# The type of the color property is set to Any using the property decorator
# vectorized_mobject.py#L571
temp_color: ManimColor = self.color # type: ignore[has-type]
temp_color: ManimColor = self.color
return temp_color


Expand Down
2 changes: 1 addition & 1 deletion manim/mobject/geometry/tips.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def tip_point(self) -> InternalPoint3D:
# Type inference of extracting an element from a list, is not
# supported by numpy, see this numpy issue
# https://github.com/numpy/numpy/issues/16544
return self.points[0] # type: ignore[no-any-return]
return self.points[0]

@property
def vector(self) -> Vector3D:
Expand Down
4 changes: 2 additions & 2 deletions manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2159,12 +2159,12 @@ def get_z(self, direction: Vector3D = ORIGIN) -> ManimFloat:
"""Returns z Point3D of the center of the :class:`~.Mobject` as ``float``"""
return self.get_coord(2, direction)

def get_start(self) -> Point3D:
def get_start(self) -> InternalPoint3D:
"""Returns the point, where the stroke that surrounds the :class:`~.Mobject` starts."""
self.throw_error_if_no_points()
return np.array(self.points[0])

def get_end(self) -> Point3D:
def get_end(self) -> InternalPoint3D:
"""Returns the point, where the stroke that surrounds the :class:`~.Mobject` ends."""
self.throw_error_if_no_points()
return np.array(self.points[-1])
Expand Down

0 comments on commit 01e566a

Please sign in to comment.