ronantakizawa/codereview-bench huggingface dataset:
Repository: ManimCommunity/manim
File: manim/renderer/shader.py (Python)

Code before:
from __future__ import annotations

import contextlib
import inspect
import re
import textwrap
from collections.abc import Iterator
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable

import moderngl
import numpy as np
import numpy.typing as npt
from cloup import Context
from moderngl import Attribute
from typing_extensions import Self

from manim.mobject.mobject import Mobject

if TYPE_CHECKING:
    from manim.renderer.opengl_renderer import OpenGLRenderer
from manim.typing import Point3D

from .. import config
from ..utils import opengl

SHADER_FOLDER = Path(__file__).parent / "shaders"
shader_program_cache: dict[Path, Any] = {}
file_path_to_code_map: dict[Path, str] = {}

__all__ = [
    "Object3D",
    "Mesh",
    "Shader",
    "FullScreenQuad",
]


def get_shader_code_from_file(file_path: Path) -> str:

Review comment (suggestion):
The contexts used in this file are not `cloup.Context`s, but rather `moderngl.Context`s.
```suggestion
```

Code after:
from __future__ import annotations

import contextlib
import inspect
import re
import textwrap
from collections.abc import Callable, Iterator, Sequence
from pathlib import Path
from typing import TYPE_CHECKING, Any

import moderngl
import numpy as np
import numpy.typing as npt
from typing_extensions import Self, TypeAlias

if TYPE_CHECKING:
    from manim.renderer.opengl_renderer import OpenGLRenderer

    MeshTimeBasedUpdater: TypeAlias = Callable[["Object3D", float], None]
    MeshNonTimeBasedUpdater: TypeAlias = Callable[["Object3D"], None]
    MeshUpdater: TypeAlias = MeshNonTimeBasedUpdater | MeshTimeBasedUpdater

from manim.typing import MatrixMN, Point3D

from .. import config
from ..utils import opengl

SHADER_FOLDER = Path(__file__).parent / "shaders"
shader_program_cache: dict[str, moderngl.Program] = {}
file_path_to_code_map: dict[Path, str] = {}

__all__ = [
    "Object3D",
    "Mesh",
    "Shader",
    "FullScreenQuad",
]
Repository: ManimCommunity/manim
File: manim/renderer/shader.py (Python)

Code before:
from __future__ import annotations

import contextlib
import inspect
import re
import textwrap
from collections.abc import Iterator
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable

import moderngl
import numpy as np
import numpy.typing as npt
from cloup import Context
from moderngl import Attribute
from typing_extensions import Self

from manim.mobject.mobject import Mobject

if TYPE_CHECKING:
    from manim.renderer.opengl_renderer import OpenGLRenderer
from manim.typing import Point3D

from .. import config
from ..utils import opengl

SHADER_FOLDER = Path(__file__).parent / "shaders"
shader_program_cache: dict[Path, Any] = {}
file_path_to_code_map: dict[Path, str] = {}

__all__ = [
    "Object3D",
    "Mesh",
    "Shader",
    "FullScreenQuad",
]


def get_shader_code_from_file(file_path: Path) -> str:
    if file_path in file_path_to_code_map:

Review comment (suggestion):
`moderngl` was already imported earlier, so I'd prefer that we removed this line and used `moderngl.Attribute` instead.
```suggestion
```

Code after:
from __future__ import annotations

import contextlib
import inspect
import re
import textwrap
from collections.abc import Callable, Iterator, Sequence
from pathlib import Path
from typing import TYPE_CHECKING, Any

import moderngl
import numpy as np
import numpy.typing as npt
from typing_extensions import Self, TypeAlias

if TYPE_CHECKING:
    from manim.renderer.opengl_renderer import OpenGLRenderer

    MeshTimeBasedUpdater: TypeAlias = Callable[["Object3D", float], None]
    MeshNonTimeBasedUpdater: TypeAlias = Callable[["Object3D"], None]
    MeshUpdater: TypeAlias = MeshNonTimeBasedUpdater | MeshTimeBasedUpdater

from manim.typing import MatrixMN, Point3D

from .. import config
from ..utils import opengl

SHADER_FOLDER = Path(__file__).parent / "shaders"
shader_program_cache: dict[str, moderngl.Program] = {}
file_path_to_code_map: dict[Path, str] = {}

__all__ = [
    "Object3D",
    "Mesh",
    "Shader",
    "FullScreenQuad",
]


def get_shader_code_from_file(file_path: Path) -> str:
Repository: ManimCommunity/manim
File: manim/renderer/shader.py (Python)

Code before:
from __future__ import annotations

import contextlib
import inspect
import re
import textwrap
from collections.abc import Iterator
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable

import moderngl
import numpy as np
import numpy.typing as npt
from cloup import Context
from moderngl import Attribute
from typing_extensions import Self

from manim.mobject.mobject import Mobject

if TYPE_CHECKING:
    from manim.renderer.opengl_renderer import OpenGLRenderer
from manim.typing import Point3D

from .. import config
from ..utils import opengl

SHADER_FOLDER = Path(__file__).parent / "shaders"
shader_program_cache: dict[Path, Any] = {}
file_path_to_code_map: dict[Path, str] = {}

__all__ = [
    "Object3D",
    "Mesh",
    "Shader",

Review comment (suggestion):
I recently noticed that `typing.Callable` is a deprecated alias of `collections.abc.Callable` and that we should try to use the latter instead:
```suggestion
from collections.abc import Callable, Iterator, Sequence
from pathlib import Path
from typing import TYPE_CHECKING, Any
```

Code after:
from __future__ import annotations

import contextlib
import inspect
import re
import textwrap
from collections.abc import Callable, Iterator, Sequence
from pathlib import Path
from typing import TYPE_CHECKING, Any

import moderngl
import numpy as np
import numpy.typing as npt
from typing_extensions import Self, TypeAlias

if TYPE_CHECKING:
    from manim.renderer.opengl_renderer import OpenGLRenderer

    MeshTimeBasedUpdater: TypeAlias = Callable[["Object3D", float], None]
    MeshNonTimeBasedUpdater: TypeAlias = Callable[["Object3D"], None]
    MeshUpdater: TypeAlias = MeshNonTimeBasedUpdater | MeshTimeBasedUpdater

from manim.typing import MatrixMN, Point3D

from .. import config
from ..utils import opengl

SHADER_FOLDER = Path(__file__).parent / "shaders"
shader_program_cache: dict[str, moderngl.Program] = {}
file_path_to_code_map: dict[Path, str] = {}

__all__ = [
    "Object3D",
    "Mesh",
Repository: ManimCommunity/manim
File: manim/mobject/opengl/opengl_surface.py (Python)

Code before:
from __future__ import annotations

from collections.abc import Iterable
from pathlib import Path

import moderngl
import numpy as np
from PIL import Image

from manim.constants import *
from manim.mobject.opengl.opengl_mobject import OpenGLMobject
from manim.typing import MatrixMN
from manim.utils.bezier import integer_interpolate, interpolate
from manim.utils.color import *
from manim.utils.config_ops import _Data, _Uniforms
from manim.utils.images import change_to_rgba_array, get_full_raster_image_path
from manim.utils.iterables import listify
from manim.utils.space_ops import normalize_along_axis

__all__ = ["OpenGLSurface", "OpenGLTexturedSurface"]


class OpenGLSurface(OpenGLMobject):
    r"""Creates a Surface.

    Parameters
    ----------
    uv_func
        The function that defines the surface.
    u_range
        The range of the ``u`` variable: ``(u_min, u_max)``.
    v_range
        The range of the ``v`` variable: ``(v_min, v_max)``.
    resolution
        The number of samples taken of the surface.
    axes
        Axes on which the surface is to be drawn. Optional

Review comment (suggestion):
```suggestion
from manim.typing import Point3D_Array, Vector3D_Array
```

Code after:
from __future__ import annotations

from collections.abc import Iterable
from pathlib import Path

import moderngl
import numpy as np
from PIL import Image

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
from manim.utils.images import change_to_rgba_array, get_full_raster_image_path
from manim.utils.iterables import listify
from manim.utils.space_ops import normalize_along_axis

__all__ = ["OpenGLSurface", "OpenGLTexturedSurface"]


class OpenGLSurface(OpenGLMobject):
    r"""Creates a Surface.

    Parameters
    ----------
    uv_func
        The function that defines the surface.
    u_range
        The range of the ``u`` variable: ``(u_min, u_max)``.
    v_range
        The range of the ``v`` variable: ``(v_min, v_max)``.
    resolution
        The number of samples taken of the surface.
    axes
        Axes on which the surface is to be drawn. Optional
Repository: ManimCommunity/manim
File: manim/renderer/opengl_renderer_window.py (Python)

Code before:
        # in the form Y/X (UR)
        if custom_position in ["LEFT", "RIGHT"]:
            custom_position = "O" + custom_position[0]
        elif custom_position in ["UP", "DOWN"]:
            custom_position = custom_position[0] + "O"
        elif custom_position == "ORIGIN":
            custom_position = "O" * 2
        elif "," in custom_position:
            pos_y, pos_x = tuple(map(int, custom_position.split(",")))
            return (pos_x, pos_y)

        # Alternatively, it might be specified with a string like
        # UR, OO, DL, etc. specifying what corner it should go to
        char_to_n = {"L": 0, "U": 0, "O": 1, "R": 2, "D": 2}
        width_diff: int = monitor.width - window_width
        height_diff: int = monitor.height - window_height

        return (
            monitor.x + char_to_n[custom_position[1]] * width_diff // 2,
            -monitor.y + char_to_n[custom_position[0]] * height_diff // 2,
        )

    def on_mouse_press(self, x: int, y: int, button: int, modifiers: int) -> None:
        super().on_mouse_press(x, y, button, modifiers)
        point = self.renderer.pixel_coords_to_space_coords(x, y)
        self.renderer.scene.on_mouse_press(point, button, modifiers)


Review comment (suggestion):
I don't believe `on_mouse_press` is used anywhere. `button` is an integer in `Scene`, so there is no need for the map unless there are plans to change this in `Scene`.

Code after:
            )
        # in the form Y/X (UR)
        if custom_position in ["LEFT", "RIGHT"]:
            custom_position = "O" + custom_position[0]
        elif custom_position in ["UP", "DOWN"]:
            custom_position = custom_position[0] + "O"
        elif custom_position == "ORIGIN":
            custom_position = "O" * 2
        elif "," in custom_position:
            pos_y, pos_x = tuple(map(int, custom_position.split(",")))
            return (pos_x, pos_y)

        # Alternatively, it might be specified with a string like
        # UR, OO, DL, etc. specifying what corner it should go to
        char_to_n = {"L": 0, "U": 0, "O": 1, "R": 2, "D": 2}
        width_diff: int = monitor.width - window_width
        height_diff: int = monitor.height - window_height

        return (
            monitor.x + char_to_n[custom_position[1]] * width_diff // 2,
            -monitor.y + char_to_n[custom_position[0]] * height_diff // 2,
        )

    def on_mouse_press(self, x: int, y: int, button: int, modifiers: int) -> None:
        super().on_mouse_press(x, y, button, modifiers)
        point = self.renderer.pixel_coords_to_space_coords(x, y)
        mouse_button_map = {
            1: "LEFT",
            2: "MOUSE",
            4: "RIGHT",
        }
        self.renderer.scene.on_mouse_press(point, mouse_button_map[button], modifiers)
Repository: ManimCommunity/manim
File: manim/mobject/text/text_mobject.py (Python)

Code before:
            x.set_opacity(0.5)
            x.submobjects[1].set_opacity(1)
            self.add(x)

"""

from __future__ import annotations

import functools

__all__ = ["Text", "Paragraph", "MarkupText", "register_font"]


import copy
import hashlib
import re
from collections.abc import Iterable, Iterator, Sequence
from contextlib import contextmanager
from itertools import chain
from pathlib import Path
from typing import TYPE_CHECKING, Any

import manimpango
import numpy as np
from manimpango import MarkupUtils, PangoUtils, TextSetting
from typing_extensions import Self

from manim import config, logger
from manim.constants import *
from manim.mobject.geometry.arc import Dot
from manim.mobject.svg.svg_mobject import SVGMobject
from manim.mobject.text.code_mobject import Code
from manim.mobject.types.vectorized_mobject import VGroup, VMobject
from manim.typing import Point3D
from manim.utils.color import ManimColor, ParsableManimColor, color_gradient

if TYPE_CHECKING:
    from typing import Any

    from typing_extensions import Self

    from manim.typing import Point3D

TEXT_MOB_SCALE_FACTOR = 0.05
DEFAULT_LINE_SPACING_SCALE = 0.3
TEXT2SVG_ADJUSTMENT_FACTOR = 4.8

__all__ = ["Text", "Paragraph", "MarkupText", "register_font"]


def remove_invisible_chars(mobject: VMobject) -> VMobject:

Review comment (refactor):
There's already a `from typing_extensions import Self` line defined inside the `if TYPE_CHECKING:` block, so let's keep that one and remove this one:
```suggestion
```

Code after:
            x.set_opacity(0.5)
            x.submobjects[1].set_opacity(1)
            self.add(x)

"""

from __future__ import annotations

import functools

__all__ = ["Text", "Paragraph", "MarkupText", "register_font"]


import copy
import hashlib
import re
from collections.abc import Iterable, Iterator, Sequence
from contextlib import contextmanager
from itertools import chain
from pathlib import Path
from typing import TYPE_CHECKING, Any

import manimpango
import numpy as np
from manimpango import MarkupUtils, PangoUtils, TextSetting

from manim import config, logger
from manim.constants import *
from manim.mobject.geometry.arc import Dot
from manim.mobject.svg.svg_mobject import SVGMobject
from manim.mobject.text.code_mobject import Code
from manim.mobject.types.vectorized_mobject import VGroup, VMobject
from manim.typing import Point3D
from manim.utils.color import ManimColor, ParsableManimColor, color_gradient

if TYPE_CHECKING:
    from typing_extensions import Self

    from manim.typing import Point3D

TEXT_MOB_SCALE_FACTOR = 0.05
DEFAULT_LINE_SPACING_SCALE = 0.3
TEXT2SVG_ADJUSTMENT_FACTOR = 4.8

__all__ = ["Text", "Paragraph", "MarkupText", "register_font"]


def remove_invisible_chars(mobject: VMobject) -> VMobject:
    """Function to remove unwanted invisible characters from some mobjects.

    Parameters
Repository: ManimCommunity/manim
File: manim/mobject/text/text_mobject.py (Python)

Code before:
import copy
import hashlib
import re
from collections.abc import Iterable, Iterator, Sequence
from contextlib import contextmanager
from itertools import chain
from pathlib import Path
from typing import TYPE_CHECKING, Any

import manimpango
import numpy as np
from manimpango import MarkupUtils, PangoUtils, TextSetting
from typing_extensions import Self

from manim import config, logger
from manim.constants import *
from manim.mobject.geometry.arc import Dot
from manim.mobject.svg.svg_mobject import SVGMobject
from manim.mobject.text.code_mobject import Code
from manim.mobject.types.vectorized_mobject import VGroup, VMobject
from manim.typing import Point3D
from manim.utils.color import ManimColor, ParsableManimColor, color_gradient

if TYPE_CHECKING:
    from typing import Any

    from typing_extensions import Self

    from manim.typing import Point3D

TEXT_MOB_SCALE_FACTOR = 0.05
DEFAULT_LINE_SPACING_SCALE = 0.3
TEXT2SVG_ADJUSTMENT_FACTOR = 4.8

__all__ = ["Text", "Paragraph", "MarkupText", "register_font"]


def remove_invisible_chars(mobject: VMobject) -> VMobject:
    """Function to remove unwanted invisible characters from some mobjects.

    Parameters
    ----------
    mobject
        Any SVGMobject from which we want to remove unwanted invisible characters.

    Returns
    -------
    :class:`~.SVGMobject`
        The SVGMobject without unwanted invisible characters.
    """
    # TODO: Refactor needed

Review comment (refactor):
`Any` was already imported outside this block along with `TYPE_CHECKING`, so let's remove this one:
```suggestion
```

Code after:
import copy
import hashlib
import re
from collections.abc import Iterable, Iterator, Sequence
from contextlib import contextmanager
from itertools import chain
from pathlib import Path
from typing import TYPE_CHECKING, Any

import manimpango
import numpy as np
from manimpango import MarkupUtils, PangoUtils, TextSetting

from manim import config, logger
from manim.constants import *
from manim.mobject.geometry.arc import Dot
from manim.mobject.svg.svg_mobject import SVGMobject
from manim.mobject.text.code_mobject import Code
from manim.mobject.types.vectorized_mobject import VGroup, VMobject
from manim.typing import Point3D
from manim.utils.color import ManimColor, ParsableManimColor, color_gradient

if TYPE_CHECKING:
    from typing_extensions import Self

    from manim.typing import Point3D

TEXT_MOB_SCALE_FACTOR = 0.05
DEFAULT_LINE_SPACING_SCALE = 0.3
TEXT2SVG_ADJUSTMENT_FACTOR = 4.8

__all__ = ["Text", "Paragraph", "MarkupText", "register_font"]


def remove_invisible_chars(mobject: VMobject) -> VMobject:
    """Function to remove unwanted invisible characters from some mobjects.

    Parameters
    ----------
    mobject
        Any SVGMobject from which we want to remove unwanted invisible characters.

    Returns
    -------
    :class:`~.SVGMobject`
        The SVGMobject without unwanted invisible characters.
    """
    # TODO: Refactor needed
    iscode = False
    if isinstance(mobject, Text):
        mobject = mobject[:]
Repository: ManimCommunity/manim
File: manim/mobject/opengl/opengl_geometry.py (Python)

Code before:
        self,
        fill_opacity: float = 1,
        fill_color: ParsableManimColor = WHITE,
        stroke_width: float = 0,
        width: float = DEFAULT_ARROW_TIP_WIDTH,
        length: float = DEFAULT_ARROW_TIP_LENGTH,
        angle: float = 0,
        **kwargs: Any,
    ):
        super().__init__(
            start_angle=0,
            fill_opacity=fill_opacity,
            fill_color=fill_color,
            stroke_width=stroke_width,
            **kwargs,
        )
        self.set_width(width, stretch=True)
        self.set_height(length, stretch=True)

    def get_base(self) -> Point3D:
        return self.point_from_proportion(0.5)

    def get_tip_point(self) -> Point3D:
        return self.points[0]

    def get_vector(self) -> Point3D:
        return self.get_tip_point() - self.get_base()

    def get_angle(self) -> float:
        return angle_of_vector(self.get_vector())

    def get_length(self) -> float:
        rv: float = np.linalg.norm(self.get_vector())
        return rv


class OpenGLRectangle(OpenGLPolygon):
    def __init__(
        self,
        color: ParsableManimColor = WHITE,
        width: float = 4.0,
        height: float = 2.0,
        **kwargs: Any,
    ):
        super().__init__(UR, UL, DL, DR, color=color, **kwargs)

        self.set_width(width, stretch=True)
        self.set_height(height, stretch=True)


class OpenGLSquare(OpenGLRectangle):

Review comment (suggestion):
```suggestion
    def get_vector(self) -> Vector3D:
```

Code after:
                self.start_angle = 90 * DEGREES
        start_vect = rotate_vector(RIGHT, self.start_angle)
        vertices = compass_directions(n, start_vect)
        super().__init__(*vertices, **kwargs)


class OpenGLTriangle(OpenGLRegularPolygon):
    def __init__(self, **kwargs: Any):
        super().__init__(n=3, **kwargs)


class OpenGLArrowTip(OpenGLTriangle):
    def __init__(
        self,
        fill_opacity: float = 1,
        fill_color: ParsableManimColor = WHITE,
        stroke_width: float = 0,
        width: float = DEFAULT_ARROW_TIP_WIDTH,
        length: float = DEFAULT_ARROW_TIP_LENGTH,
        angle: float = 0,
        **kwargs: Any,
    ):
        super().__init__(
            start_angle=0,
            fill_opacity=fill_opacity,
            fill_color=fill_color,
            stroke_width=stroke_width,
            **kwargs,
        )
        self.set_width(width, stretch=True)
        self.set_height(length, stretch=True)

    def get_base(self) -> Point3D:
        return self.point_from_proportion(0.5)

    def get_tip_point(self) -> Point3D:
        return self.points[0]

    def get_vector(self) -> Vector3D:
        return self.get_tip_point() - self.get_base()

    def get_angle(self) -> float:
        return angle_of_vector(self.get_vector())

    def get_length(self) -> float:
        rv: float = np.linalg.norm(self.get_vector())
        return rv


class OpenGLRectangle(OpenGLPolygon):
    def __init__(
Repository: ManimCommunity/manim
File: manim/mobject/three_d/three_dimensions.py (Python)

Code before:
    Examples
    --------
    .. manim:: ExampleArrow3D
        :save_last_frame:

        class ExampleArrow3D(ThreeDScene):
            def construct(self):
                axes = ThreeDAxes()
                arrow = Arrow3D(
                    start=np.array([0, 0, 0]),
                    end=np.array([2, 2, 2]),
                    resolution=8
                )
                self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
                self.add(axes, arrow)
    """

    def __init__(
        self,
        start: np.ndarray = LEFT,
        end: np.ndarray = RIGHT,
        thickness: float = 0.02,
        height: float = 0.3,
        base_radius: float = 0.08,
        color: ParsableManimColor = WHITE,
        resolution: int | Sequence[int] = 24,
        **kwargs: Any,
    ) -> None:
        super().__init__(
            start=start,
            end=end,
            thickness=thickness,
            color=color,
            resolution=resolution,
            **kwargs,
        )

        self.length = np.linalg.norm(self.vect)
        self.set_start_and_end_attrs(
            self.start,
            self.end - height * self.direction,
            **kwargs,
        )
        self.cone = Cone(
            direction=self.direction,
            base_radius=base_radius,
            height=height,
            **kwargs,
        )
        np_end = np.asarray(end, dtype=np.float64)
        self.cone.shift(np_end)

Review comment (suggestion):
```suggestion
        resolution: int | tuple[int, int] = 24,
```

Code after:
    --------
    .. manim:: ExampleArrow3D
        :save_last_frame:

        class ExampleArrow3D(ThreeDScene):
            def construct(self):
                axes = ThreeDAxes()
                arrow = Arrow3D(
                    start=np.array([0, 0, 0]),
                    end=np.array([2, 2, 2]),
                    resolution=8
                )
                self.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
                self.add(axes, arrow)
    """

    def __init__(
        self,
        start: Point3DLike = LEFT,
        end: Point3DLike = RIGHT,
        thickness: float = 0.02,
        height: float = 0.3,
        base_radius: float = 0.08,
        color: ParsableManimColor = WHITE,
        resolution: int | tuple[int, int] = 24,
        **kwargs: Any,
    ) -> None:
        super().__init__(
            start=start,
            end=end,
            thickness=thickness,
            color=color,
            resolution=resolution,
            **kwargs,
        )

        self.length = np.linalg.norm(self.vect)
        self.set_start_and_end_attrs(
            self.start,
            self.end - height * self.direction,
            **kwargs,
        )
        self.cone = Cone(
            direction=self.direction,
            base_radius=base_radius,
            height=height,
            **kwargs,
        )
        np_end = np.asarray(end, dtype=np.float64)
        self.cone.shift(np_end)
        self.end_point = VectorizedPoint(np_end)