A community-maintained Python framework for creating mathematical animations.
pre-commit change to ruff (#3779)
adeshpande24025b60d573
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlindex cdf84ef89..de2a017cf 100644--- a/.pre-commit-config.yaml+++ b/.pre-commit-config.yaml@@ -34,16 +34,11 @@ repos:hooks:- id: python-check-blanket-noqaname: Precision flake ignores- - repo: https://github.com/psf/black- rev: 24.4.2+ - repo: https://github.com/astral-sh/ruff-pre-commit+ rev: v0.4.4hooks:- - id: black- - repo: https://github.com/asottile/blacken-docs- rev: 1.16.0- hooks:- - id: blacken-docs- additional_dependencies: [black==24.4.0]- exclude: ^\.github/+ - id: ruff-format+ types: [python]- repo: https://github.com/PyCQA/flake8rev: 7.0.0hooks:diff --git a/example_scenes/basic.py b/example_scenes/basic.pyindex e61ae01f6..6e8c866f4 100644--- a/example_scenes/basic.py+++ b/example_scenes/basic.py@@ -153,7 +153,7 @@ class SpiralInExample(Scene):],color=PURPLE_B,fill_opacity=1,- stroke_width=0+ stroke_width=0,).shift(UP + 2 * RIGHT)shapes = VGroup(triangle, square, circle, pentagon, pi)self.play(SpiralIn(shapes, fade_in_fraction=0.9))diff --git a/manim/_config/__init__.py b/manim/_config/__init__.pyindex 18a57307b..3eed54b48 100644--- a/manim/_config/__init__.py+++ b/manim/_config/__init__.py@@ -68,7 +68,6 @@ def tempconfig(temp: ManimConfig | dict[str, Any]) -> Generator[None, None, None8.0>>> with tempconfig({"frame_height": 100.0}):... print(config["frame_height"])- ...100.0>>> config["frame_height"]8.0diff --git a/manim/_config/cli_colors.py b/manim/_config/cli_colors.pyindex e1d9fb02f..c39f24d71 100644--- a/manim/_config/cli_colors.py+++ b/manim/_config/cli_colors.py@@ -35,15 +35,18 @@ def parse_cli_ctx(parser: configparser.SectionProxy) -> Context:theme = parser["theme"] if parser["theme"] else Noneif theme is None:formatter = HelpFormatter.settings(- theme=HelpTheme(**theme_settings), **formatter_settings # type: ignore[arg-type]+ theme=HelpTheme(**theme_settings),+ **formatter_settings, # type: ignore[arg-type])elif theme.lower() == "dark":formatter = HelpFormatter.settings(- theme=HelpTheme.dark().with_(**theme_settings), **formatter_settings # type: ignore[arg-type]+ theme=HelpTheme.dark().with_(**theme_settings),+ **formatter_settings, # type: ignore[arg-type])elif theme.lower() == "light":formatter = HelpFormatter.settings(- theme=HelpTheme.light().with_(**theme_settings), **formatter_settings # type: ignore[arg-type]+ theme=HelpTheme.light().with_(**theme_settings),+ **formatter_settings, # type: ignore[arg-type])return Context.settings(diff --git a/manim/mobject/geometry/tips.py b/manim/mobject/geometry/tips.pyindex 725e9535a..a7f116d3b 100644--- a/manim/mobject/geometry/tips.py+++ b/manim/mobject/geometry/tips.py@@ -60,8 +60,9 @@ class ArrowTip(VMobject, metaclass=ConvertToOpenGL):... RegularPolygon.__init__(self, n=5, **kwargs)... self.width = length... self.stretch_to_fit_height(length)- >>> arr = Arrow(np.array([-2, -2, 0]), np.array([2, 2, 0]),- ... tip_shape=MyCustomArrowTip)+ >>> arr = Arrow(+ ... np.array([-2, -2, 0]), np.array([2, 2, 0]), tip_shape=MyCustomArrowTip+ ... )>>> isinstance(arr.tip, RegularPolygon)True>>> from manim import Scene, Creatediff --git a/manim/mobject/graph.py b/manim/mobject/graph.pyindex bc11ec69e..53d7ed464 100644--- a/manim/mobject/graph.py+++ b/manim/mobject/graph.py@@ -1513,7 +1513,8 @@ class Graph(GenericGraph):*new_edges,vertex_config=self.VERTEX_CONF,positions={- k: g.vertices[vertex_id].get_center() + 0.1 * DOWN for k in new_vertices+ k: g.vertices[vertex_id].get_center() + 0.1 * DOWN+ for k in new_vertices},)if depth < self.DEPTH:diff --git a/manim/mobject/graphing/coordinate_systems.py b/manim/mobject/graphing/coordinate_systems.pyindex 6315093f2..3330193a4 100644--- a/manim/mobject/graphing/coordinate_systems.py+++ b/manim/mobject/graphing/coordinate_systems.py@@ -394,7 +394,9 @@ class CoordinateSystem:ax = ThreeDAxes()x_labels = range(-4, 5)z_labels = range(-4, 4, 2)- ax.add_coordinates(x_labels, None, z_labels) # default y labels, custom x & z labels+ ax.add_coordinates(+ x_labels, None, z_labels+ ) # default y labels, custom x & z labelsax.add_coordinates(x_labels) # only x labelsYou can also specifically control the position and value of the labels using a dict.@@ -405,7 +407,15 @@ class CoordinateSystem:x_pos = [x for x in range(1, 8)]# strings are automatically converted into a Tex mobject.- x_vals = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]+ x_vals = [+ "Monday",+ "Tuesday",+ "Wednesday",+ "Thursday",+ "Friday",+ "Saturday",+ "Sunday",+ ]x_dict = dict(zip(x_pos, x_vals))ax.add_coordinates(x_dict)"""diff --git a/manim/mobject/graphing/number_line.py b/manim/mobject/graphing/number_line.pyindex 63c8954b1..834f3086c 100644--- a/manim/mobject/graphing/number_line.py+++ b/manim/mobject/graphing/number_line.py@@ -364,7 +364,7 @@ class NumberLine(Line):array([0., 0., 0.])>>> number_line.number_to_point(1)array([1., 0., 0.])- >>> number_line.number_to_point([1,2,3])+ >>> number_line.number_to_point([1, 2, 3])array([[1., 0., 0.],[2., 0., 0.],[3., 0., 0.]])@@ -396,11 +396,11 @@ class NumberLine(Line):>>> from manim import NumberLine>>> number_line = NumberLine()- >>> number_line.point_to_number((0,0,0))+ >>> number_line.point_to_number((0, 0, 0))0.0- >>> number_line.point_to_number((1,0,0))+ >>> number_line.point_to_number((1, 0, 0))1.0- >>> number_line.point_to_number([[0.5,0,0],[1,0,0],[1.5,0,0]])+ >>> number_line.point_to_number([[0.5, 0, 0], [1, 0, 0], [1.5, 0, 0]])array([0.5, 1. , 1.5])"""diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.pyindex 0ae2a29da..6e405a18e 100644--- a/manim/mobject/mobject.py+++ b/manim/mobject/mobject.py@@ -2064,7 +2064,7 @@ class Mobject:::- sample = Arc(start_angle=PI/7, angle = PI/5)+ sample = Arc(start_angle=PI / 7, angle=PI / 5)# These are all equivalentmax_y_1 = sample.get_top()[1]diff --git a/manim/mobject/text/text_mobject.py b/manim/mobject/text/text_mobject.pyindex 971200a11..39a1cdd17 100644--- a/manim/mobject/text/text_mobject.py+++ b/manim/mobject/text/text_mobject.py@@ -135,10 +135,17 @@ class Paragraph(VGroup):--------Normal usage::- paragraph = Paragraph('this is a awesome', 'paragraph',- 'With \nNewlines', '\tWith Tabs',- ' With Spaces', 'With Alignments',- 'center', 'left', 'right')+ paragraph = Paragraph(+ "this is a awesome",+ "paragraph",+ "With \nNewlines",+ "\tWith Tabs",+ " With Spaces",+ "With Alignments",+ "center",+ "left",+ "right",+ )Remove unwanted invisible characters::@@ -1305,15 +1312,13 @@ class MarkupText(SVGMobject):self.set_color_by_gradient(*self.gradient)for col in colormap:self.chars[- col["start"]- - col["start_offset"] : col["end"]+ col["start"] - col["start_offset"] : col["end"]- col["start_offset"]- col["end_offset"]].set_color(self._parse_color(col["color"]))for grad in gradientmap:self.chars[- grad["start"]- - grad["start_offset"] : grad["end"]+ grad["start"] - grad["start_offset"] : grad["end"]- grad["start_offset"]- grad["end_offset"]].set_color_by_gradient(diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.pyindex d82346868..f32e88aaa 100644--- a/manim/mobject/types/vectorized_mobject.py+++ b/manim/mobject/types/vectorized_mobject.py@@ -1926,19 +1926,21 @@ class VGroup(VMobject, metaclass=ConvertToOpenGL):>>> triangle, square = Triangle(), Square()>>> vg.add(triangle)VGroup(Triangle)- >>> vg + square # a new VGroup is constructed+ >>> vg + square # a new VGroup is constructedVGroup(Triangle, Square)- >>> vg # not modified+ >>> vg # not modifiedVGroup(Triangle)- >>> vg += square; vg # modifies vg+ >>> vg += square+ >>> vg # modifies vgVGroup(Triangle, Square)>>> vg.remove(triangle)VGroup(Square)- >>> vg - square; # a new VGroup is constructed+ >>> vg - square # a new VGroup is constructedVGroup()- >>> vg # not modified+ >>> vg # not modifiedVGroup(Square)- >>> vg -= square; vg # modifies vg+ >>> vg -= square+ >>> vg # modifies vgVGroup().. manim:: ArcShapeIris@@ -2200,7 +2202,7 @@ class VDict(VMobject, metaclass=ConvertToOpenGL):Normal usage::square_obj = Square()- my_dict.add([('s', square_obj)])+ my_dict.add([("s", square_obj)])"""for key, value in dict(mapping_or_iterable).items():self.add_key_value_pair(key, value)@@ -2227,7 +2229,7 @@ class VDict(VMobject, metaclass=ConvertToOpenGL):--------Normal usage::- my_dict.remove('square')+ my_dict.remove("square")"""if key not in self.submob_dict:raise KeyError("The given key '%s' is not present in the VDict" % str(key))@@ -2252,7 +2254,7 @@ class VDict(VMobject, metaclass=ConvertToOpenGL):--------Normal usage::- self.play(Create(my_dict['s']))+ self.play(Create(my_dict["s"]))"""submob = self.submob_dict[key]return submob@@ -2276,7 +2278,7 @@ class VDict(VMobject, metaclass=ConvertToOpenGL):Normal usage::square_obj = Square()- my_dict['sq'] = square_obj+ my_dict["sq"] = square_obj"""if key in self.submob_dict:self.remove(key)@@ -2381,7 +2383,7 @@ class VDict(VMobject, metaclass=ConvertToOpenGL):Normal usage::square_obj = Square()- self.add_key_value_pair('s', square_obj)+ self.add_key_value_pair("s", square_obj)"""self._assert_valid_submobjects([value])diff --git a/manim/scene/scene.py b/manim/scene/scene.pyindex 06dd15fc9..1f5faed4e 100644--- a/manim/scene/scene.py+++ b/manim/scene/scene.py@@ -1555,8 +1555,7 @@ class Scene:# second option: within the call to Scene.playself.play(- Transform(square, circle),- subcaption="The square transforms."+ Transform(square, circle), subcaption="The square transforms.")"""diff --git a/manim/scene/scene_file_writer.py b/manim/scene/scene_file_writer.pyindex ebd7d13ca..3b58d2c73 100644--- a/manim/scene/scene_file_writer.py+++ b/manim/scene/scene_file_writer.py@@ -715,7 +715,6 @@ class SceneFileWriter:av.open(movie_file_path) as video_input,av.open(sound_file_path) as audio_input,):-video_stream = video_input.streams.video[0]audio_stream = audio_input.streams.audio[0]output_container = av.open(diff --git a/manim/utils/color/X11.py b/manim/utils/color/X11.pyindex 06d7c7575..0379717ea 100644--- a/manim/utils/color/X11.py+++ b/manim/utils/color/X11.py@@ -22,6 +22,7 @@ List of Color Constants.. automanimcolormodule:: manim.utils.color.X11"""+from .core import ManimColorALICEBLUE = ManimColor("#F0F8FF")diff --git a/manim/utils/color/core.py b/manim/utils/color/core.pyindex d2312c6f5..32c895d10 100644--- a/manim/utils/color/core.py+++ b/manim/utils/color/core.py@@ -147,7 +147,8 @@ class ManimColor:else:if length == 3:self._internal_value = ManimColor._internal_from_int_rgb(- value, alpha # type: ignore+ value,+ alpha, # type: ignore)elif length == 4:self._internal_value = ManimColor._internal_from_int_rgba(value) # type: ignorediff --git a/manim/utils/deprecation.py b/manim/utils/deprecation.pyindex ece4d4034..2d443c5e7 100644--- a/manim/utils/deprecation.py+++ b/manim/utils/deprecation.py@@ -105,10 +105,12 @@ def deprecated(from manim.utils.deprecation import deprecated+@deprecateddef foo(**kwargs):pass+@deprecatedclass Bar:def __init__(self):@@ -118,6 +120,7 @@ def deprecated(def baz(self):pass+foo()# WARNING The function foo has been deprecated and may be removed in a later version.@@ -131,15 +134,12 @@ def deprecated(from manim.utils.deprecation import deprecated- @deprecated(- since="v0.2",- until="v0.4",- replacement="bar",- message="It is cooler."- )++ @deprecated(since="v0.2", until="v0.4", replacement="bar", message="It is cooler.")def foo():pass+foo()# WARNING The function foo has been deprecated since v0.2 and is expected to be removed after v0.4. Use bar instead. It is cooler.@@ -147,10 +147,12 @@ def deprecated(from manim.utils.deprecation import deprecated+@deprecated(since="05/01/2021", until="06/01/2021")def foo():pass+foo()# WARNING The function foo has been deprecated since 05/01/2021 and is expected to be removed after 06/01/2021.@@ -234,9 +236,8 @@ def deprecated_params(since: str | None = None,until: str | None = None,message: str | None = "",- redirections: None | (- Iterable[tuple[str, str] | Callable[..., dict[str, Any]]]- ) = None,+ redirections: None+ | (Iterable[tuple[str, str] | Callable[..., dict[str, Any]]]) = None,) -> Callable:"""Decorator to mark parameters of a callable as deprecated.@@ -287,10 +288,12 @@ def deprecated_params(from manim.utils.deprecation import deprecated_params+@deprecated_params(params="a, b, c")def foo(**kwargs):pass+foo(x=2, y=3, z=4)# No warning@@ -301,15 +304,17 @@ def deprecated_params(from manim.utils.deprecation import deprecated_params+@deprecated_params(params="a, b, c",since="v0.2",until="v0.4",- message="The letters x, y, z are cooler."+ message="The letters x, y, z are cooler.",)def foo(**kwargs):pass+foo(a=2)# WARNING The parameter a of method foo has been deprecated since v0.2 and is expected to be removed after v0.4. The letters x, y, z are cooler.@@ -317,14 +322,18 @@ def deprecated_params(from manim.utils.deprecation import deprecated_params- @deprecated_params(redirections=[- # Two ways to redirect one parameter to another:- ("old_param", "new_param"),- lambda old_param2: {"new_param22": old_param2}- ])++ @deprecated_params(+ redirections=[+ # Two ways to redirect one parameter to another:+ ("old_param", "new_param"),+ lambda old_param2: {"new_param22": old_param2},+ ]+ )def foo(**kwargs):return kwargs+foo(x=1, old_param=2)# WARNING The parameter old_param of method foo has been deprecated and may be removed in a later version.# returns {"x": 1, "new_param": 2}@@ -333,12 +342,14 @@ def deprecated_params(from manim.utils.deprecation import deprecated_params- @deprecated_params(redirections=[- lambda runtime_in_ms: {"run_time": runtime_in_ms / 1000}- ])++ @deprecated_params(+ redirections=[lambda runtime_in_ms: {"run_time": runtime_in_ms / 1000}]+ )def foo(**kwargs):return kwargs+foo(runtime_in_ms=500)# WARNING The parameter runtime_in_ms of method foo has been deprecated and may be removed in a later version.# returns {"run_time": 0.5}@@ -347,12 +358,14 @@ def deprecated_params(from manim.utils.deprecation import deprecated_params- @deprecated_params(redirections=[- lambda buff_x=1, buff_y=1: {"buff": (buff_x, buff_y)}- ])++ @deprecated_params(+ redirections=[lambda buff_x=1, buff_y=1: {"buff": (buff_x, buff_y)}]+ )def foo(**kwargs):return kwargs+foo(buff_x=2)# WARNING The parameter buff_x of method foo has been deprecated and may be removed in a later version.# returns {"buff": (2, 1)}@@ -361,18 +374,23 @@ def deprecated_params(from manim.utils.deprecation import deprecated_params- @deprecated_params(redirections=[- lambda buff=1: {"buff_x": buff[0], "buff_y": buff[1]} if isinstance(buff, tuple)- else {"buff_x": buff, "buff_y": buff}- ])++ @deprecated_params(+ redirections=[+ lambda buff=1: {"buff_x": buff[0], "buff_y": buff[1]}+ if isinstance(buff, tuple)+ else {"buff_x": buff, "buff_y": buff}+ ]+ )def foo(**kwargs):return kwargs+foo(buff=0)# WARNING The parameter buff of method foo has been deprecated and may be removed in a later version.# returns {"buff_x": 0, buff_y: 0}- foo(buff=(1,2))+ foo(buff=(1, 2))# WARNING The parameter buff of method foo has been deprecated and may be removed in a later version.# returns {"buff_x": 1, buff_y: 2}diff --git a/manim/utils/docbuild/module_parsing.py b/manim/utils/docbuild/module_parsing.pyindex 8ff7c0fe5..87bfa76c4 100644--- a/manim/utils/docbuild/module_parsing.py+++ b/manim/utils/docbuild/module_parsing.py@@ -125,8 +125,7 @@ def parse_module_attributes() -> tuple[AliasDocsDict, DataDict]:and ((# if TYPE_CHECKING- type(node.test) is ast.Name- and node.test.id == "TYPE_CHECKING"+ type(node.test) is ast.Name and node.test.id == "TYPE_CHECKING")or (# if typing.TYPE_CHECKINGdiff --git a/manim/utils/space_ops.py b/manim/utils/space_ops.pyindex 3df699bec..ec47d136e 100644--- a/manim/utils/space_ops.py+++ b/manim/utils/space_ops.py@@ -622,7 +622,7 @@ def get_winding_number(points: Sequence[np.ndarray]) -> float:>>> polygon = Square()>>> get_winding_number(polygon.get_vertices())1.0- >>> polygon.shift(2*UP)+ >>> polygon.shift(2 * UP)Square>>> get_winding_number(polygon.get_vertices())0.0diff --git a/tests/module/mobject/text/test_markup.py b/tests/module/mobject/text/test_markup.pyindex abe1d9333..78c42ed18 100644--- a/tests/module/mobject/text/test_markup.py+++ b/tests/module/mobject/text/test_markup.py@@ -22,9 +22,7 @@ def test_special_tags_markup():success = Trueexcept ValueError:success = False- assert (- success- ), '\'<color col="RED">foo</color>\' and \'<gradient from="RED" to="YELLOW">foo</gradient>\' should not fail validation'+ assert success, '\'<color col="RED">foo</color>\' and \'<gradient from="RED" to="YELLOW">foo</gradient>\' should not fail validation'def test_unbalanced_tag_markup():diff --git a/tests/opengl/test_markup_opengl.py b/tests/opengl/test_markup_opengl.pyindex b8a0e1c9f..b96acbeb9 100644--- a/tests/opengl/test_markup_opengl.py+++ b/tests/opengl/test_markup_opengl.py@@ -22,9 +22,7 @@ def test_special_tags_markup(using_opengl_renderer):success = Trueexcept ValueError:success = False- assert (- success- ), '\'<color col="RED">foo</color>\' and \'<gradient from="RED" to="YELLOW">foo</gradient>\' should not fail validation'+ assert success, '\'<color col="RED">foo</color>\' and \'<gradient from="RED" to="YELLOW">foo</gradient>\' should not fail validation'def test_unbalanced_tag_markup(using_opengl_renderer):diff --git a/tests/test_scene_rendering/opengl/test_cli_flags_opengl.py b/tests/test_scene_rendering/opengl/test_cli_flags_opengl.pyindex e9a5d7e96..5b3a299dc 100644--- a/tests/test_scene_rendering/opengl/test_cli_flags_opengl.py+++ b/tests/test_scene_rendering/opengl/test_cli_flags_opengl.py@@ -342,9 +342,7 @@ def test_a_flag(tmp_path, manim_cfg_file, infallible_scenes_path):two_is_not_empty = (tmp_path / "images" / "infallible_scenes" / f"Wait2_ManimCE_v{__version__}.png").is_file()- assert (- two_is_not_empty- ), "running manim with -a flag did not render an image, possible leak of the config dictionary"+ assert two_is_not_empty, "running manim with -a flag did not render an image, possible leak of the config dictionary"three_is_not_empty = (tmp_path / "videos" / "infallible_scenes" / "480p15" / "Wait3.mp4"diff --git a/tests/test_scene_rendering/test_cli_flags.py b/tests/test_scene_rendering/test_cli_flags.pyindex aaee0276a..c9516c6fc 100644--- a/tests/test_scene_rendering/test_cli_flags.py+++ b/tests/test_scene_rendering/test_cli_flags.py@@ -239,9 +239,7 @@ def test_a_flag(tmp_path, manim_cfg_file, infallible_scenes_path):two_is_not_empty = (tmp_path / "images" / "infallible_scenes" / f"Wait2_ManimCE_v{__version__}.png").is_file()- assert (- two_is_not_empty- ), "running manim with -a flag did not render an image, possible leak of the config dictionary."+ assert two_is_not_empty, "running manim with -a flag did not render an image, possible leak of the config dictionary."three_is_not_empty = (tmp_path / "videos" / "infallible_scenes" / "480p15" / "Wait3.mp4"