From 07bbe3f2200d42fe1a575ad7362163538a07ec84 Mon Sep 17 00:00:00 2001 From: Henrik Skov Midtiby Date: Tue, 22 Oct 2024 14:07:36 +0200 Subject: [PATCH] Removed several type ignore statements and addressed comments from JasonGrace2282 --- manim/mobject/geometry/arc.py | 21 +++++++++++-------- manim/mobject/geometry/boolean_ops.py | 4 ++-- manim/mobject/geometry/line.py | 30 ++++++++++++--------------- manim/mobject/geometry/polygram.py | 6 +++--- manim/mobject/geometry/tips.py | 2 +- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/manim/mobject/geometry/arc.py b/manim/mobject/geometry/arc.py index 1c1f5ec743..9529135f35 100644 --- a/manim/mobject/geometry/arc.py +++ b/manim/mobject/geometry/arc.py @@ -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() @@ -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 + temp_angle: float = ( + angle_of_vector(self.points[-1] - self.get_arc_center()) % TAU + ) + return temp_angle class ArcBetweenPoints(Arc): @@ -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 @@ -658,7 +661,7 @@ def construct(self): perpendicular_bisector([np.array(p1), np.array(p2)]), perpendicular_bisector([np.array(p2), np.array(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) diff --git a/manim/mobject/geometry/boolean_ops.py b/manim/mobject/geometry/boolean_ops.py index b6b24c7806..ce9e81ffec 100644 --- a/manim/mobject/geometry/boolean_ops.py +++ b/manim/mobject/geometry/boolean_ops.py @@ -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 @@ -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 diff --git a/manim/mobject/geometry/line.py b/manim/mobject/geometry/line.py index cd9d786306..a15bccd05a 100644 --- a/manim/mobject/geometry/line.py +++ b/manim/mobject/geometry/line.py @@ -90,7 +90,8 @@ def set_points_by_ends( if path_arc: # self.path_arc could potentially be None, which is not accepted # as parameter. - arc = ArcBetweenPoints(self.start, self.end, angle=self.path_arc) # type: ignore[arg-type] + assert self.path_arc is not None + arc = ArcBetweenPoints(self.start, self.end, angle=self.path_arc) self.set_points(arc.points) else: self.set_points_as_corners(np.array([self.start, self.end])) @@ -144,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: @@ -155,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. @@ -308,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() @@ -323,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() @@ -337,10 +338,7 @@ def get_first_handle(self) -> InternalPoint3D: >>> DashedLine().get_first_handle() array([-0.98333333, 0. , 0. ]) """ - # 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. @@ -352,10 +350,7 @@ def get_last_handle(self) -> InternalPoint3D: >>> DashedLine().get_last_handle() array([0.98333333, 0. , 0. ]) """ - # 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): @@ -548,7 +543,7 @@ def __init__( self.max_tip_length_to_length_ratio = max_tip_length_to_length_ratio self.max_stroke_width_to_length_ratio = max_stroke_width_to_length_ratio tip_shape = kwargs.pop("tip_shape", ArrowTriangleFilledTip) - super().__init__(*args, buff=buff, stroke_width=stroke_width, **kwargs) + super().__init__(*args, buff=buff, stroke_width=stroke_width, **kwargs) # type: ignore[misc] # TODO, should this be affected when # Arrow.set_stroke is called? self.initial_stroke_width = self.stroke_width @@ -1072,7 +1067,8 @@ def construct(self): self.add(line1, line2, angle, value) """ - return self.angle_value / DEGREES if degrees else self.angle_value + temp_angle: float = self.angle_value / DEGREES if degrees else self.angle_value + return temp_angle @staticmethod def from_three_points(A: Point3D, B: Point3D, C: Point3D, **kwargs: Any) -> Angle: diff --git a/manim/mobject/geometry/polygram.py b/manim/mobject/geometry/polygram.py index 593657fe5f..e8e2e04562 100644 --- a/manim/mobject/geometry/polygram.py +++ b/manim/mobject/geometry/polygram.py @@ -88,7 +88,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) @@ -321,7 +321,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): @@ -412,7 +412,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): diff --git a/manim/mobject/geometry/tips.py b/manim/mobject/geometry/tips.py index 6c54a1da64..e137016a88 100644 --- a/manim/mobject/geometry/tips.py +++ b/manim/mobject/geometry/tips.py @@ -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: