Skip to content

Use ruff instead of flake8-simplify #3873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
5 changes: 1 addition & 4 deletions manim/_config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions manim/animation/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions manim/animation/fading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions manim/animation/specialized.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions manim/cli/cfg/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from __future__ import annotations

import contextlib
from ast import literal_eval
from pathlib import Path

Expand Down Expand Up @@ -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


Expand Down
5 changes: 1 addition & 4 deletions manim/mobject/geometry/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions manim/mobject/geometry/polygram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 4 additions & 13 deletions manim/mobject/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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),
)
for v in vertices
]
Expand Down
5 changes: 1 addition & 4 deletions manim/mobject/graphing/probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1996,7 +1994,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
Expand All @@ -2005,10 +2003,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]:
Expand Down
5 changes: 1 addition & 4 deletions manim/mobject/opengl/opengl_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions manim/mobject/opengl/opengl_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 1 addition & 4 deletions manim/mobject/opengl/opengl_vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
*(
Expand Down
5 changes: 1 addition & 4 deletions manim/mobject/text/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 2 additions & 8 deletions manim/mobject/three_d/three_dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions manim/mobject/types/vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions manim/opengl/__init__.py
Original file line number Diff line number Diff line change
@@ -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 *
Expand Down
5 changes: 2 additions & 3 deletions manim/renderer/opengl_renderer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import contextlib
import itertools as it
import time
from functools import cached_property
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions manim/renderer/shader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import contextlib
import inspect
import re
import textwrap
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 1 addition & 4 deletions manim/scene/scene_file_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions manim/utils/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion manim/utils/docbuild/autoaliasattr_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]


Expand Down
5 changes: 1 addition & 4 deletions manim/utils/docbuild/autocolor_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
Loading
Loading