From b6d111896aafefdc3be4ea5cd734c5ebe85954f1 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Thu, 18 Jul 2024 23:05:58 -0400 Subject: [PATCH 1/3] pyproject --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c38f80daef..32086f7b23 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,7 +69,6 @@ flake8-builtins = "^2.2.0" flake8-comprehensions = "^3.7.0" flake8-docstrings = "^1.7.0" flake8-pytest-style = "^1.7.2" -flake8-simplify = "^0.14.1" flake8-rst-docstrings = "^0.3.0" furo = "^2023.09.10" gitpython = "^3" @@ -139,6 +138,7 @@ select = [ "E", "F", "I", + "SIM", "UP", ] From 2403bce77036524e07d596e341a699be9b6ea034 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Thu, 18 Jul 2024 23:10:47 -0400 Subject: [PATCH 2/3] Autofixes from pre-commit --- docs/source/conf.py | 2 +- manim/_config/utils.py | 5 +---- manim/animation/creation.py | 5 +---- manim/animation/fading.py | 5 +---- manim/animation/specialized.py | 5 +---- manim/cli/cfg/group.py | 5 ++--- manim/mobject/geometry/line.py | 5 +---- manim/mobject/geometry/polygram.py | 5 +---- manim/mobject/graph.py | 17 ++++------------- manim/mobject/graphing/probability.py | 5 +---- manim/mobject/mobject.py | 11 +++-------- manim/mobject/opengl/opengl_geometry.py | 5 +---- manim/mobject/opengl/opengl_mobject.py | 9 ++------- .../mobject/opengl/opengl_vectorized_mobject.py | 5 +---- manim/mobject/text/numbers.py | 5 +---- manim/mobject/three_d/three_dimensions.py | 10 ++-------- manim/mobject/types/vectorized_mobject.py | 11 +++-------- manim/opengl/__init__.py | 6 +++--- manim/renderer/opengl_renderer.py | 5 ++--- manim/renderer/shader.py | 5 ++--- manim/scene/scene_file_writer.py | 5 +---- manim/utils/bezier.py | 4 +--- manim/utils/docbuild/autoaliasattr_directive.py | 2 +- manim/utils/docbuild/autocolor_directive.py | 5 +---- manim/utils/docbuild/manim_directive.py | 6 +----- manim/utils/space_ops.py | 5 +---- scripts/dev_changelog.py | 4 ++-- 27 files changed, 42 insertions(+), 120 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 3910fd7ed1..4f6a3fe891 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -63,7 +63,7 @@ alias_name: f"~manim.{module}.{alias_name}" for module, module_dict in ALIAS_DOCS_DICT.items() for category_dict in module_dict.values() - for alias_name in category_dict.keys() + for alias_name in category_dict } autoclass_content = "both" diff --git a/manim/_config/utils.py b/manim/_config/utils.py index 46613e8d74..ab2e3edf05 100644 --- a/manim/_config/utils.py +++ b/manim/_config/utils.py @@ -654,10 +654,7 @@ def digest_parser(self, parser: configparser.ConfigParser) -> Self: # plugins plugins = parser["CLI"].get("plugins", fallback="", raw=True) - if plugins == "": - plugins = [] - else: - plugins = plugins.split(",") + plugins = [] if plugins == "" else plugins.split(",") self.plugins = plugins # the next two must be set AFTER digesting pixel_width and pixel_height self["frame_height"] = parser["CLI"].getfloat("frame_height", 8.0) diff --git a/manim/animation/creation.py b/manim/animation/creation.py index e6f7199bf2..124d3295f6 100644 --- a/manim/animation/creation.py +++ b/manim/animation/creation.py @@ -351,10 +351,7 @@ def _set_default_config_from_length( ) -> tuple[float, float]: length = len(vmobject.family_members_with_points()) if run_time is None: - if length < 15: - run_time = 1 - else: - run_time = 2 + run_time = 1 if length < 15 else 2 if lag_ratio is None: lag_ratio = min(4.0 / max(1.0, length), 0.2) return run_time, lag_ratio diff --git a/manim/animation/fading.py b/manim/animation/fading.py index 1e98b2c295..c09d8bac64 100644 --- a/manim/animation/fading.py +++ b/manim/animation/fading.py @@ -57,10 +57,7 @@ def __init__( ) -> None: if not mobjects: raise ValueError("At least one mobject must be passed.") - if len(mobjects) == 1: - mobject = mobjects[0] - else: - mobject = Group(*mobjects) + mobject = mobjects[0] if len(mobjects) == 1 else Group(*mobjects) self.point_target = False if shift is None: diff --git a/manim/animation/specialized.py b/manim/animation/specialized.py index 99320f36d9..e5f9e96d96 100644 --- a/manim/animation/specialized.py +++ b/manim/animation/specialized.py @@ -70,10 +70,7 @@ def __init__( anims = [] # Works by saving the mob that is passed into the animation, scaling it to 0 (or the initial_width) and then restoring the original mob. - if mobject.fill_opacity: - fill_o = True - else: - fill_o = False + fill_o = bool(mobject.fill_opacity) for _ in range(self.n_mobs): mob = mobject.copy() diff --git a/manim/cli/cfg/group.py b/manim/cli/cfg/group.py index 346205d89f..24b98a835b 100644 --- a/manim/cli/cfg/group.py +++ b/manim/cli/cfg/group.py @@ -8,6 +8,7 @@ from __future__ import annotations +import contextlib from ast import literal_eval from pathlib import Path @@ -51,10 +52,8 @@ def value_from_string(value: str) -> str | int | bool: Union[:class:`str`, :class:`int`, :class:`bool`] Returns the literal of appropriate datatype. """ - try: + with contextlib.suppress(SyntaxError, ValueError): value = literal_eval(value) - except (SyntaxError, ValueError): - pass return value diff --git a/manim/mobject/geometry/line.py b/manim/mobject/geometry/line.py index 50d63c1190..7009dd5b31 100644 --- a/manim/mobject/geometry/line.py +++ b/manim/mobject/geometry/line.py @@ -98,10 +98,7 @@ def _account_for_buff(self, buff: float) -> Self: if buff == 0: return # - if self.path_arc == 0: - length = self.get_length() - else: - length = self.get_arc_length() + length = self.get_length() if self.path_arc == 0 else self.get_arc_length() # if length < 2 * buff: return diff --git a/manim/mobject/geometry/polygram.py b/manim/mobject/geometry/polygram.py index de48c28998..0a9edbadd7 100644 --- a/manim/mobject/geometry/polygram.py +++ b/manim/mobject/geometry/polygram.py @@ -757,9 +757,6 @@ def construct(self): def __init__(self, main_shape: VMobject, *mobjects: VMobject, **kwargs) -> None: super().__init__(**kwargs) self.append_points(main_shape.points) - if main_shape.get_direction() == "CW": - sub_direction = "CCW" - else: - sub_direction = "CW" + sub_direction = "CCW" if main_shape.get_direction() == "CW" else "CW" for mobject in mobjects: self.append_points(mobject.force_direction(sub_direction).points) diff --git a/manim/mobject/graph.py b/manim/mobject/graph.py index 72a26d27db..26c1d57f78 100644 --- a/manim/mobject/graph.py +++ b/manim/mobject/graph.py @@ -338,10 +338,7 @@ def _tree_layout( parent = {u: root_vertex for u in children[root_vertex]} pos = {} obstruction = [0.0] * len(T) - if orientation == "down": - o = -1 - else: - o = 1 + o = -1 if orientation == "down" else 1 def slide(v, dx): """ @@ -404,15 +401,9 @@ def slide(v, dx): if isinstance(scale, (float, int)) and (width > 0 or height > 0): sf = 2 * scale / max(width, height) elif isinstance(scale, tuple): - if scale[0] is not None and width > 0: - sw = 2 * scale[0] / width - else: - sw = 1 + sw = 2 * scale[0] / width if scale[0] is not None and width > 0 else 1 - if scale[1] is not None and height > 0: - sh = 2 * scale[1] / height - else: - sh = 1 + sh = 2 * scale[1] / height if scale[1] is not None and height > 0 else 1 sf = np.array([sw, sh, 0]) else: @@ -851,7 +842,7 @@ def _create_vertices( label_fill_color=label_fill_color, vertex_type=vertex_type, vertex_config=vertex_config[v], - vertex_mobject=vertex_mobjects[v] if v in vertex_mobjects else None, + vertex_mobject=vertex_mobjects.get(v, None), ) for v in vertices ] diff --git a/manim/mobject/graphing/probability.py b/manim/mobject/graphing/probability.py index 0f98620dc3..42197b8ff0 100644 --- a/manim/mobject/graphing/probability.py +++ b/manim/mobject/graphing/probability.py @@ -339,10 +339,7 @@ def _add_x_axis_labels(self): for i, (value, bar_name) in enumerate(zip(val_range, self.bar_names)): # to accommodate negative bars, the label may need to be # below or above the x_axis depending on the value of the bar - if self.values[i] < 0: - direction = UP - else: - direction = DOWN + direction = UP if self.values[i] < 0 else DOWN bar_name_label = self.x_axis.label_constructor(bar_name) bar_name_label.font_size = self.x_axis.font_size diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py index ee487a7fc5..2983b89153 100644 --- a/manim/mobject/mobject.py +++ b/manim/mobject/mobject.py @@ -1579,9 +1579,7 @@ def is_off_screen(self): return True if self.get_bottom()[1] > config["frame_y_radius"]: return True - if self.get_top()[1] < -config["frame_y_radius"]: - return True - return False + return self.get_top()[1] < -config["frame_y_radius"] def stretch_about_point(self, factor: float, dim: int, point: Point3D) -> Self: return self.stretch(factor, dim, about_point=point) @@ -1995,7 +1993,7 @@ def reduce_across_dimension(self, reduce_func: Callable, dim: int): # If we do not have points (but do have submobjects) # use only the points from those. - if len(self.points) == 0: + if len(self.points) == 0: # noqa: SIM108 rv = None else: # Otherwise, be sure to include our own points @@ -2004,10 +2002,7 @@ def reduce_across_dimension(self, reduce_func: Callable, dim: int): # smallest dimension they have and compare it to the return value. for mobj in self.submobjects: value = mobj.reduce_across_dimension(reduce_func, dim) - if rv is None: - rv = value - else: - rv = reduce_func([value, rv]) + rv = value if rv is None else reduce_func([value, rv]) return rv def nonempty_submobjects(self) -> list[Self]: diff --git a/manim/mobject/opengl/opengl_geometry.py b/manim/mobject/opengl/opengl_geometry.py index 2ec0bbe4dd..646594a29c 100644 --- a/manim/mobject/opengl/opengl_geometry.py +++ b/manim/mobject/opengl/opengl_geometry.py @@ -463,10 +463,7 @@ def account_for_buff(self, buff): if buff == 0: return # - if self.path_arc == 0: - length = self.get_length() - else: - length = self.get_arc_length() + length = self.get_length() if self.path_arc == 0 else self.get_arc_length() # if length < 2 * buff: return diff --git a/manim/mobject/opengl/opengl_mobject.py b/manim/mobject/opengl/opengl_mobject.py index c907c4c2e0..135b6cb6e3 100644 --- a/manim/mobject/opengl/opengl_mobject.py +++ b/manim/mobject/opengl/opengl_mobject.py @@ -1868,9 +1868,7 @@ def is_off_screen(self) -> bool: return True if self.get_bottom()[1] > config.frame_y_radius: return True - if self.get_top()[1] < -config.frame_y_radius: - return True - return False + return self.get_top()[1] < -config.frame_y_radius def stretch_about_point(self, factor: float, dim: int, point: Point3D) -> Self: return self.stretch(factor, dim, about_point=point) @@ -2569,10 +2567,7 @@ def construct(self): if key not in mobject1.data or key not in mobject2.data: continue - if key in ("points", "bounding_box"): - func = path_func - else: - func = interpolate + func = path_func if key in ("points", "bounding_box") else interpolate self.data[key][:] = func(mobject1.data[key], mobject2.data[key], alpha) diff --git a/manim/mobject/opengl/opengl_vectorized_mobject.py b/manim/mobject/opengl/opengl_vectorized_mobject.py index 8037760c4a..82c863779d 100644 --- a/manim/mobject/opengl/opengl_vectorized_mobject.py +++ b/manim/mobject/opengl/opengl_vectorized_mobject.py @@ -1874,10 +1874,7 @@ def __init__( if num_dashes > 0: # Assuming total length is 1 dash_len = r / n - if vmobject.is_closed(): - void_len = (1 - r) / n - else: - void_len = (1 - r) / (n - 1) + void_len = (1 - r) / n if vmobject.is_closed() else (1 - r) / (n - 1) self.add( *( diff --git a/manim/mobject/text/numbers.py b/manim/mobject/text/numbers.py index 6a0eb45a82..05854dfb43 100644 --- a/manim/mobject/text/numbers.py +++ b/manim/mobject/text/numbers.py @@ -210,10 +210,7 @@ def _get_num_string(self, number): rounded_num = np.round(number, self.num_decimal_places) if num_string.startswith("-") and rounded_num == 0: - if self.include_sign: - num_string = "+" + num_string[1:] - else: - num_string = num_string[1:] + num_string = "+" + num_string[1:] if self.include_sign else num_string[1:] return num_string diff --git a/manim/mobject/three_d/three_dimensions.py b/manim/mobject/three_d/three_dimensions.py index bcdde3e188..86238551f3 100644 --- a/manim/mobject/three_d/three_dimensions.py +++ b/manim/mobject/three_d/three_dimensions.py @@ -667,10 +667,7 @@ def _rotate_to_direction(self) -> None: x, y, z = self.direction r = np.sqrt(x**2 + y**2 + z**2) - if r > 0: - theta = np.arccos(z / r) - else: - theta = 0 + theta = np.arccos(z / r) if r > 0 else 0 if x == 0: if y == 0: # along the z axis @@ -835,10 +832,7 @@ def _rotate_to_direction(self) -> None: x, y, z = self.direction r = np.sqrt(x**2 + y**2 + z**2) - if r > 0: - theta = np.arccos(z / r) - else: - theta = 0 + theta = np.arccos(z / r) if r > 0 else 0 if x == 0: if y == 0: # along the z axis diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py index 86b5cd1386..5346d5e7ba 100644 --- a/manim/mobject/types/vectorized_mobject.py +++ b/manim/mobject/types/vectorized_mobject.py @@ -1200,9 +1200,7 @@ def consider_points_equals_2d(self, p0: Point2D, p1: Point2D) -> bool: atol = self.tolerance_for_point_equality if abs(p0[0] - p1[0]) > atol + rtol * abs(p1[0]): return False - if abs(p0[1] - p1[1]) > atol + rtol * abs(p1[1]): - return False - return True + return abs(p0[1] - p1[1]) <= atol + rtol * abs(p1[1]) # Information about line def get_cubic_bezier_tuples_from_points( @@ -2709,15 +2707,12 @@ def __init__( if vmobject.is_closed(): void_len = (1 - r) / n else: - if n == 1: - void_len = 1 - r - else: - void_len = (1 - r) / (n - 1) + void_len = 1 - r if n == 1 else (1 - r) / (n - 1) period = dash_len + void_len phase_shift = (dash_offset % 1) * period - if vmobject.is_closed(): + if vmobject.is_closed(): # noqa: SIM108 # closed curves have equal amount of dashes and voids pattern_len = 1 else: diff --git a/manim/opengl/__init__.py b/manim/opengl/__init__.py index 83f6a4ccde..e5bad5cd2c 100644 --- a/manim/opengl/__init__.py +++ b/manim/opengl/__init__.py @@ -1,9 +1,9 @@ from __future__ import annotations -try: +import contextlib + +with contextlib.suppress(ImportError): from dearpygui import dearpygui as dpg -except ImportError: - pass from manim.mobject.opengl.dot_cloud import * diff --git a/manim/renderer/opengl_renderer.py b/manim/renderer/opengl_renderer.py index 8347f8a49e..453fa4906c 100644 --- a/manim/renderer/opengl_renderer.py +++ b/manim/renderer/opengl_renderer.py @@ -1,5 +1,6 @@ from __future__ import annotations +import contextlib import itertools as it import time from functools import cached_property @@ -336,10 +337,8 @@ def render_mobject(self, mobject): shader_wrapper.uniforms.items(), self.perspective_uniforms.items(), ): - try: + with contextlib.suppress(KeyError): shader.set_uniform(name, value) - except KeyError: - pass try: shader.set_uniform( "u_view_matrix", self.scene.camera.formatted_view_matrix diff --git a/manim/renderer/shader.py b/manim/renderer/shader.py index 85b9dad14a..a098ed30ca 100644 --- a/manim/renderer/shader.py +++ b/manim/renderer/shader.py @@ -1,5 +1,6 @@ from __future__ import annotations +import contextlib import inspect import re import textwrap @@ -382,10 +383,8 @@ def __init__( shader_program_cache[self.name] = self.shader_program def set_uniform(self, name, value): - try: + with contextlib.suppress(KeyError): self.shader_program[name] = value - except KeyError: - pass class FullScreenQuad(Mesh): diff --git a/manim/scene/scene_file_writer.py b/manim/scene/scene_file_writer.py index 9a2d5eb606..bc7b715c49 100644 --- a/manim/scene/scene_file_writer.py +++ b/manim/scene/scene_file_writer.py @@ -94,10 +94,7 @@ def init_output_directories(self, scene_name): if config["dry_run"]: # in dry-run mode there is no output return - if config["input_file"]: - module_name = config.get_dir("input_file").stem - else: - module_name = "" + module_name = config.get_dir("input_file").stem if config["input_file"] else "" if SceneFileWriter.force_output_as_scene_name: self.output_name = Path(scene_name) diff --git a/manim/utils/bezier.py b/manim/utils/bezier.py index 5a4049b654..5d5a3bad8b 100644 --- a/manim/utils/bezier.py +++ b/manim/utils/bezier.py @@ -1825,9 +1825,7 @@ def is_closed(points: Point3D_Array) -> bool: return False if abs(end[1] - start[1]) > tolerance[1]: return False - if abs(end[2] - start[2]) > tolerance[2]: - return False - return True + return abs(end[2] - start[2]) <= tolerance[2] def proportions_along_bezier_curve_for_point( diff --git a/manim/utils/docbuild/autoaliasattr_directive.py b/manim/utils/docbuild/autoaliasattr_directive.py index ba42bd1ec4..5735dc9798 100644 --- a/manim/utils/docbuild/autoaliasattr_directive.py +++ b/manim/utils/docbuild/autoaliasattr_directive.py @@ -21,7 +21,7 @@ alias_name for module_dict in ALIAS_DOCS_DICT.values() for category_dict in module_dict.values() - for alias_name in category_dict.keys() + for alias_name in category_dict ] diff --git a/manim/utils/docbuild/autocolor_directive.py b/manim/utils/docbuild/autocolor_directive.py index 574aaedf77..3a699f54d4 100644 --- a/manim/utils/docbuild/autocolor_directive.py +++ b/manim/utils/docbuild/autocolor_directive.py @@ -69,10 +69,7 @@ def run(self) -> list[nodes.Element]: luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b # Choose the font color based on the background luminance - if luminance > 0.5: - font_color = "black" - else: - font_color = "white" + font_color = "black" if luminance > 0.5 else "white" color_elements.append((member_name, member_obj.to_hex(), font_color)) diff --git a/manim/utils/docbuild/manim_directive.py b/manim/utils/docbuild/manim_directive.py index cd277970e3..7ca7d68647 100644 --- a/manim/utils/docbuild/manim_directive.py +++ b/manim/utils/docbuild/manim_directive.py @@ -225,11 +225,7 @@ def run(self) -> list[nodes.Element]: + self.options.get("ref_functions", []) + self.options.get("ref_methods", []) ) - if ref_content: - ref_block = "References: " + " ".join(ref_content) - - else: - ref_block = "" + ref_block = "References: " + " ".join(ref_content) if ref_content else "" if "quality" in self.options: quality = f'{self.options["quality"]}_quality' diff --git a/manim/utils/space_ops.py b/manim/utils/space_ops.py index 197621fce6..955256f10c 100644 --- a/manim/utils/space_ops.py +++ b/manim/utils/space_ops.py @@ -476,10 +476,7 @@ def regular_vertices( """ if start_angle is None: - if n % 2 == 0: - start_angle = 0 - else: - start_angle = TAU / 4 + start_angle = 0 if n % 2 == 0 else TAU / 4 start_vector = rotate_vector(RIGHT * radius, start_angle) vertices = compass_directions(n, start_vector) diff --git a/scripts/dev_changelog.py b/scripts/dev_changelog.py index 35e77dd798..a4a18b934e 100755 --- a/scripts/dev_changelog.py +++ b/scripts/dev_changelog.py @@ -110,7 +110,7 @@ def process_pullrequests(lst, cur, github_repo, pr_nums): authors.add(pr.user) reviewers = reviewers.union(rev.user for rev in pr.get_reviews()) pr_labels = [label.name for label in pr.labels] - for label in PR_LABELS.keys(): + for label in PR_LABELS: if label in pr_labels: pr_by_labels[label].append(pr) break # ensure that PR is only added in one category @@ -291,7 +291,7 @@ def main(token, prior, tag, additional, outfile): ) pr_by_labels = contributions["PRs"] - for label in PR_LABELS.keys(): + for label in PR_LABELS: pr_of_label = pr_by_labels[label] if pr_of_label: From 691491e26896d5bfb6c3c069b82d26d76c7c410c Mon Sep 17 00:00:00 2001 From: adeshpande <110117391+JasonGrace2282@users.noreply.github.com> Date: Mon, 22 Jul 2024 06:08:25 -0400 Subject: [PATCH 3/3] use get over get(x, None) Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com> --- manim/mobject/graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/mobject/graph.py b/manim/mobject/graph.py index b1b408e97f..3c98936127 100644 --- a/manim/mobject/graph.py +++ b/manim/mobject/graph.py @@ -842,7 +842,7 @@ def _create_vertices( label_fill_color=label_fill_color, vertex_type=vertex_type, vertex_config=vertex_config[v], - vertex_mobject=vertex_mobjects.get(v, None), + vertex_mobject=vertex_mobjects.get(v), ) for v in vertices ]