Repository: ManimCommunity/manim
File: manim/mobject/geometry.py (Python)

Code before:
    close_new_points : :class:`bool`, optional
        No purpose.
    kwargs : Any
        Additional arguments to be passed to :class:`Polygon`

    Examples
    ----------

    .. manim:: RectangleExample
        :save_last_frame:

        class RectangleExample(Scene):
            def construct(self):
                rect1 = Rectangle(width=4.0, height=2.0)
                rect2 = Rectangle(width=1.0, height=4.0)

                rects = Group(rect1,rect2).arrange(buff=1)
                self.add(rects)
    """

    def __init__(
        self,
        color: Color = WHITE,
        height: float = 2.0,
        width: float = 4.0,
        grid_xstep: float = 0,
        grid_ystep: float = 0,
        mark_paths_closed=True,
        close_new_points=True,
        **kwargs,
    ):
        self.mark_paths_closed = mark_paths_closed
        self.close_new_points = close_new_points
        super().__init__(UR, UL, DL, DR, color=color, **kwargs)
        self.stretch_to_fit_width(width)
        self.stretch_to_fit_height(height)
        v = self.get_vertices()
        if grid_xstep != 0:
            count = int(width / grid_xstep)
            grid = VGroup(
                *[
                    Line(
                        v[1] + i * grid_xstep * RIGHT,
                        v[1] + i * grid_xstep * RIGHT + height * DOWN,
                        color=color,
                    )
                    for i in range(1, count)
                ]
            )
            self.add(grid)
        if grid_ystep != 0:

Review comment (suggestion):
A semantical issue: In the docstring (where typings actually are not necessary, as they are generated automatically when rendering the documentation from the type hints in the function header) the parameter is indicated as "float, optional" -- which means it should be `Optional[float]` here.

This would allow for the default value to be `None` -- which I would actually prefer over 0 (because the spacing between grid lines technically isn't 0 in that case; there *is* no spacing). :-)

Code after:
        No purpose.
    close_new_points : :class:`bool`, optional
        No purpose.
    kwargs : Any
        Additional arguments to be passed to :class:`Polygon`

    Examples
    ----------

    .. manim:: RectangleExample
        :save_last_frame:

        class RectangleExample(Scene):
            def construct(self):
                rect1 = Rectangle(width=4.0, height=2.0, grid_xstep=1.0, grid_ystep=0.5)
                rect2 = Rectangle(width=1.0, height=4.0)

                rects = Group(rect1,rect2).arrange(buff=1)
                self.add(rects)
    """

    def __init__(
        self,
        color: Color = WHITE,
        height: float = 2.0,
        width: float = 4.0,
        grid_xstep: Optional[float] = None,
        grid_ystep: Optional[float] = None,
        mark_paths_closed=True,
        close_new_points=True,
        **kwargs,
    ):
        self.mark_paths_closed = mark_paths_closed
        self.close_new_points = close_new_points
        super().__init__(UR, UL, DL, DR, color=color, **kwargs)
        self.stretch_to_fit_width(width)
        self.stretch_to_fit_height(height)
        v = self.get_vertices()
        if grid_xstep is not None:
            grid_xstep = abs(grid_xstep)
            count = int(width / grid_xstep)
            grid = VGroup(
                *[
                    Line(
                        v[1] + i * grid_xstep * RIGHT,
                        v[1] + i * grid_xstep * RIGHT + height * DOWN,
                        color=color,
                    )
                    for i in range(1, count)
                ]
            )