From 0c7882aad49d5e83d150464a0528895f1c2f21c2 Mon Sep 17 00:00:00 2001 From: "F. Muenkel" <25496279+fmuenkel@users.noreply.github.com> Date: Sun, 18 Jan 2026 22:22:58 +0100 Subject: [PATCH 1/2] Add type annotations to opengl_image_mobject.py --- manim/mobject/opengl/opengl_image_mobject.py | 20 ++++++++++++-------- manim/mobject/opengl/opengl_surface.py | 13 +++++++++---- mypy.ini | 2 +- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/manim/mobject/opengl/opengl_image_mobject.py b/manim/mobject/opengl/opengl_image_mobject.py index 84e3ef7ad6..d7617d3ffb 100644 --- a/manim/mobject/opengl/opengl_image_mobject.py +++ b/manim/mobject/opengl/opengl_image_mobject.py @@ -5,6 +5,7 @@ ] from pathlib import Path +from typing import TYPE_CHECKING, Any import numpy as np from PIL import Image @@ -13,26 +14,29 @@ from manim.mobject.opengl.opengl_surface import OpenGLSurface, OpenGLTexturedSurface from manim.utils.images import get_full_raster_image_path +if TYPE_CHECKING: + import numpy.typing as npt + __all__ = ["OpenGLImageMobject"] class OpenGLImageMobject(OpenGLTexturedSurface): def __init__( self, - filename_or_array: str | Path | np.ndarray, - width: float = None, - height: float = None, + filename_or_array: str | Path | npt.NDArray, + width: float | None = None, + height: float | None = None, image_mode: str = "RGBA", - resampling_algorithm: int = Resampling.BICUBIC, + resampling_algorithm: Resampling = Resampling.BICUBIC, opacity: float = 1, gloss: float = 0, shadow: float = 0, - **kwargs, + **kwargs: Any, ): self.image = filename_or_array self.resampling_algorithm = resampling_algorithm if isinstance(filename_or_array, np.ndarray): - self.size = self.image.shape[1::-1] + self.size = filename_or_array.shape[1::-1] elif isinstance(filename_or_array, (str, Path)): path = get_full_raster_image_path(filename_or_array) self.size = Image.open(path).size @@ -68,7 +72,7 @@ def get_image_from_file( self, image_file: str | Path | np.ndarray, image_mode: str, - ): + ) -> Image.Image: if isinstance(image_file, (str, Path)): return super().get_image_from_file(image_file, image_mode) else: @@ -76,7 +80,7 @@ def get_image_from_file( Image.fromarray(image_file.astype("uint8")) .convert(image_mode) .resize( - np.array(image_file.shape[:2]) + image_file.shape[:2] * 200, # assumption of 200 ppmu (pixels per manim unit) would suffice resample=self.resampling_algorithm, ) diff --git a/manim/mobject/opengl/opengl_surface.py b/manim/mobject/opengl/opengl_surface.py index e6fdeee456..27084635c2 100644 --- a/manim/mobject/opengl/opengl_surface.py +++ b/manim/mobject/opengl/opengl_surface.py @@ -2,6 +2,7 @@ from collections.abc import Iterable from pathlib import Path +from typing import TYPE_CHECKING import moderngl import numpy as np @@ -9,7 +10,6 @@ from manim.constants import * from manim.mobject.opengl.opengl_mobject import OpenGLMobject -from manim.typing import Point3D_Array, Vector3D_Array from manim.utils.bezier import integer_interpolate, interpolate from manim.utils.color import * from manim.utils.config_ops import _Data, _Uniforms @@ -17,6 +17,11 @@ from manim.utils.iterables import listify from manim.utils.space_ops import normalize_along_axis +if TYPE_CHECKING: + import numpy.typing as npt + + from manim.typing import Point3D_Array, Vector3D_Array + __all__ = ["OpenGLSurface", "OpenGLTexturedSurface"] @@ -83,7 +88,7 @@ def __init__( render_primitive=moderngl.TRIANGLES, depth_test=True, shader_folder=None, - **kwargs, + **kwargs: Any, ): self.passed_uv_func = uv_func self.u_range = u_range if u_range is not None else (0, 1) @@ -374,7 +379,7 @@ class OpenGLTexturedSurface(OpenGLSurface): def __init__( self, uv_surface: OpenGLSurface, - image_file: str | Path, + image_file: str | Path | npt.NDArray, dark_image_file: str | Path = None, image_mode: str | Iterable[str] = "RGBA", shader_folder: str | Path = None, @@ -416,7 +421,7 @@ def get_image_from_file( self, image_file: str | Path, image_mode: str, - ): + ) -> Image.Image: image_file = get_full_raster_image_path(image_file) return Image.open(image_file).convert(image_mode) diff --git a/mypy.ini b/mypy.ini index 4977b894e7..8a72aef448 100644 --- a/mypy.ini +++ b/mypy.ini @@ -119,7 +119,7 @@ ignore_errors = True ignore_errors = True [mypy-manim.mobject.opengl.opengl_image_mobject] -ignore_errors = True +ignore_errors = False [mypy-manim.mobject.opengl.opengl_point_cloud_mobject] ignore_errors = True From 069899666bc64cc137f835b8c3b5da64c52e72f3 Mon Sep 17 00:00:00 2001 From: "F. Muenkel" <25496279+fmuenkel@users.noreply.github.com> Date: Sun, 18 Jan 2026 22:23:41 +0100 Subject: [PATCH 2/2] Remove mypy entry --- mypy.ini | 3 --- 1 file changed, 3 deletions(-) diff --git a/mypy.ini b/mypy.ini index 8a72aef448..48a4d9c799 100644 --- a/mypy.ini +++ b/mypy.ini @@ -118,9 +118,6 @@ ignore_errors = True [mypy-manim.mobject.opengl.opengl_compatibility] ignore_errors = True -[mypy-manim.mobject.opengl.opengl_image_mobject] -ignore_errors = False - [mypy-manim.mobject.opengl.opengl_point_cloud_mobject] ignore_errors = True