From 74f79a42b67bbee7f329fe4f3ec3ee768fba7740 Mon Sep 17 00:00:00 2001 From: Aarush Deshpande <110117391+JasonGrace2282@users.noreply.github.com> Date: Sun, 1 Sep 2024 11:55:22 -0400 Subject: [PATCH] Use Ruff pygrep rules (#3923) * Add config for ruff pygrep * Fix pygrep linting errors --- .pre-commit-config.yaml | 5 ----- example_scenes/opengl.py | 2 +- manim/cli/render/commands.py | 2 +- manim/cli/render/render_options.py | 2 +- manim/utils/bezier.py | 6 +++--- manim/utils/color/core.py | 8 ++++---- manim/utils/docbuild/manim_directive.py | 2 +- pyproject.toml | 5 +---- tests/test_scene_rendering/opengl/test_opengl_renderer.py | 2 +- 9 files changed, 13 insertions(+), 21 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index aeabc54ac6..a4c90fccb0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,11 +12,6 @@ repos: - id: end-of-file-fixer - id: check-toml name: Validate Poetry - - repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.10.0 - hooks: - - id: python-check-blanket-noqa - name: Precision flake ignores - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.6.2 hooks: diff --git a/example_scenes/opengl.py b/example_scenes/opengl.py index 27f579a6e4..baa59899cf 100644 --- a/example_scenes/opengl.py +++ b/example_scenes/opengl.py @@ -2,7 +2,7 @@ import manim.utils.opengl as opengl from manim import * -from manim.opengl import * # type: ignore +from manim.opengl import * # Copied from https://3b1b.github.io/manim/getting_started/example_scenes.html#surfaceexample. # Lines that do not yet work with the Community Version are commented. diff --git a/manim/cli/render/commands.py b/manim/cli/render/commands.py index b5659766a0..4a1810a11d 100644 --- a/manim/cli/render/commands.py +++ b/manim/cli/render/commands.py @@ -39,7 +39,7 @@ @cloup.argument("scene_names", required=False, nargs=-1) @global_options @output_options -@render_options # type: ignore +@render_options @ease_of_access_options def render( **args, diff --git a/manim/cli/render/render_options.py b/manim/cli/render/render_options.py index 21a91ce393..fabcb8d877 100644 --- a/manim/cli/render/render_options.py +++ b/manim/cli/render/render_options.py @@ -72,7 +72,7 @@ def validate_resolution(ctx, param, value): "--quality", default=None, type=Choice( - list(reversed([q["flag"] for q in QUALITIES.values() if q["flag"]])), # type: ignore + reversed([q["flag"] for q in QUALITIES.values() if q["flag"]]), # type: ignore[arg-type] case_sensitive=False, ), help="Render quality at the follow resolution framerates, respectively: " diff --git a/manim/utils/bezier.py b/manim/utils/bezier.py index e45c0bf5df..b12e6e52cb 100644 --- a/manim/utils/bezier.py +++ b/manim/utils/bezier.py @@ -1113,7 +1113,7 @@ def match_interpolate( return interpolate( new_start, new_end, - old_alpha, # type: ignore + old_alpha, # type: ignore[arg-type] ) @@ -1900,7 +1900,7 @@ def proportions_along_bezier_curve_for_point( # Roots will be none, but in this specific instance, we don't need to consider that. continue bezier_polynom = np.polynomial.Polynomial(terms[::-1]) - polynom_roots = bezier_polynom.roots() # type: ignore + polynom_roots = bezier_polynom.roots() if len(polynom_roots) > 0: polynom_roots = np.around(polynom_roots, int(np.log10(1 / round_to))) roots.append(polynom_roots) @@ -1908,7 +1908,7 @@ def proportions_along_bezier_curve_for_point( roots = [[root for root in rootlist if root.imag == 0] for rootlist in roots] # Get common roots # arg-type: ignore - roots = reduce(np.intersect1d, roots) # type: ignore + roots = reduce(np.intersect1d, roots) result = np.asarray([r.real for r in roots if 0 <= r.real <= 1]) return result diff --git a/manim/utils/color/core.py b/manim/utils/color/core.py index 4c012c140f..63c1605dc1 100644 --- a/manim/utils/color/core.py +++ b/manim/utils/color/core.py @@ -163,9 +163,9 @@ def __init__( length = len(value) if all(isinstance(x, float) for x in value): if length == 3: - self._internal_value = ManimColor._internal_from_rgb(value, alpha) # type: ignore + self._internal_value = ManimColor._internal_from_rgb(value, alpha) # type: ignore[arg-type] elif length == 4: - self._internal_value = ManimColor._internal_from_rgba(value) # type: ignore + self._internal_value = ManimColor._internal_from_rgba(value) # type: ignore[arg-type] else: raise ValueError( f"ManimColor only accepts lists/tuples/arrays of length 3 or 4, not {length}" @@ -173,11 +173,11 @@ def __init__( else: if length == 3: self._internal_value = ManimColor._internal_from_int_rgb( - value, # type: ignore + value, # type: ignore[arg-type] alpha, ) elif length == 4: - self._internal_value = ManimColor._internal_from_int_rgba(value) # type: ignore + self._internal_value = ManimColor._internal_from_int_rgba(value) # type: ignore[arg-type] else: raise ValueError( f"ManimColor only accepts lists/tuples/arrays of length 3 or 4, not {length}" diff --git a/manim/utils/docbuild/manim_directive.py b/manim/utils/docbuild/manim_directive.py index 7ca7d68647..4576be81dd 100644 --- a/manim/utils/docbuild/manim_directive.py +++ b/manim/utils/docbuild/manim_directive.py @@ -92,7 +92,7 @@ def construct(self): import jinja2 from docutils import nodes -from docutils.parsers.rst import Directive, directives # type: ignore +from docutils.parsers.rst import Directive, directives from docutils.statemachine import StringList from manim import QUALITIES diff --git a/pyproject.toml b/pyproject.toml index b7f2973303..1419d1c68e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -133,6 +133,7 @@ select = [ "E", "F", "I", + "PGH", "PT", "SIM", "UP", @@ -202,7 +203,3 @@ convention = "numpy" [tool.ruff.format] docstring-code-format = true - -[tool.codespell] -write-changes = true -ignore-words-list = ["medias", "nam"] diff --git a/tests/test_scene_rendering/opengl/test_opengl_renderer.py b/tests/test_scene_rendering/opengl/test_opengl_renderer.py index 71454d225f..f2236cb04d 100644 --- a/tests/test_scene_rendering/opengl/test_opengl_renderer.py +++ b/tests/test_scene_rendering/opengl/test_opengl_renderer.py @@ -23,7 +23,7 @@ def test_write_to_movie_disables_window( assert_file_exists(config.output_file) -@pytest.mark.skip(reason="Temporarily skip due to failing in Windows CI") # type: ignore +@pytest.mark.skip(reason="Temporarily skip due to failing in Windows CI") def test_force_window_opengl_render_with_movies( config, using_temp_opengl_config,