Skip to content

Commit d6dac76

Browse files
Change flake8-comprehensions and flake8-bugbear to ruff (#3882)
* Add config for bugbear/comprehensions note: flake8-comprehensions has 0 changes to the files * Safe fixes from pre-commit * Manual changes to make pre-commit pass * Remove deps from pyproject
1 parent 3aad355 commit d6dac76

File tree

19 files changed

+48
-38
lines changed

19 files changed

+48
-38
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ repos:
3232
- id: flake8
3333
additional_dependencies:
3434
[
35-
flake8-bugbear==21.4.3,
3635
flake8-builtins==1.5.3,
37-
flake8-comprehensions>=3.6.1,
3836
flake8-docstrings==1.6.0,
3937
flake8-pytest-style==1.5.0,
4038
flake8-rst-docstrings==0.2.3,

manim/_config/utils.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -643,14 +643,14 @@ def digest_parser(self, parser: configparser.ConfigParser) -> Self:
643643
gui_location = tuple(
644644
map(int, re.split(r"[;,\-]", parser["CLI"]["gui_location"])),
645645
)
646-
setattr(self, "gui_location", gui_location)
646+
self.gui_location = gui_location
647647

648648
window_size = parser["CLI"][
649649
"window_size"
650650
] # if not "default", get a tuple of the position
651651
if window_size != "default":
652652
window_size = tuple(map(int, re.split(r"[;,\-]", window_size)))
653-
setattr(self, "window_size", window_size)
653+
self.window_size = window_size
654654

655655
# plugins
656656
plugins = parser["CLI"].get("plugins", fallback="", raw=True)
@@ -671,7 +671,7 @@ def digest_parser(self, parser: configparser.ConfigParser) -> Self:
671671

672672
val = parser["CLI"].get("progress_bar")
673673
if val:
674-
setattr(self, "progress_bar", val)
674+
self.progress_bar = val
675675

676676
val = parser["ffmpeg"].get("loglevel")
677677
if val:
@@ -681,11 +681,11 @@ def digest_parser(self, parser: configparser.ConfigParser) -> Self:
681681
val = parser["jupyter"].getboolean("media_embed")
682682
except ValueError:
683683
val = None
684-
setattr(self, "media_embed", val)
684+
self.media_embed = val
685685

686686
val = parser["jupyter"].get("media_width")
687687
if val:
688-
setattr(self, "media_width", val)
688+
self.media_width = val
689689

690690
val = parser["CLI"].get("quality", fallback="", raw=True)
691691
if val:
@@ -836,15 +836,12 @@ def digest_args(self, args: argparse.Namespace) -> Self:
836836
if args.tex_template:
837837
self.tex_template = TexTemplate.from_file(args.tex_template)
838838

839-
if (
840-
self.renderer == RendererType.OPENGL
841-
and getattr(args, "write_to_movie") is None
842-
):
839+
if self.renderer == RendererType.OPENGL and args.write_to_movie is None:
843840
# --write_to_movie was not passed on the command line, so don't generate video.
844841
self["write_to_movie"] = False
845842

846843
# Handle --gui_location flag.
847-
if getattr(args, "gui_location") is not None:
844+
if args.gui_location is not None:
848845
self.gui_location = args.gui_location
849846

850847
return self

manim/cli/cfg/group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def write(level: str = None, openfile: bool = False) -> None:
196196
"""Not enough values in input.
197197
You may have added a new entry to default.cfg, in which case you will have to
198198
modify write_cfg_subcmd_input to account for it.""",
199-
)
199+
) from None
200200
if temp:
201201
while temp and not _is_expected_datatype(
202202
temp,

manim/cli/default_group.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def command(self, *args, **kwargs):
6767
warnings.warn(
6868
"Use default param of DefaultGroup or set_default_command() instead",
6969
DeprecationWarning,
70+
stacklevel=1,
7071
)
7172

7273
def _decorator(f):

manim/mobject/geometry/arc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,9 @@ def get_arc_center(self, warning: bool = True) -> Point3D:
400400
return line_intersection(line1=(a1, a1 + n1), line2=(a2, a2 + n2))
401401
except Exception:
402402
if warning:
403-
warnings.warn("Can't find Arc center, using ORIGIN instead")
403+
warnings.warn(
404+
"Can't find Arc center, using ORIGIN instead", stacklevel=1
405+
)
404406
self._failed_to_get_center = True
405407
return np.array(ORIGIN)
406408

manim/mobject/geometry/boolean_ops.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def _convert_vmobject_to_skia_path(self, vmobject: VMobject) -> SkiaPath:
9090
quads = vmobject.get_bezier_tuples_from_points(subpath)
9191
start = subpath[0]
9292
path.moveTo(*start[:2])
93-
for p0, p1, p2 in quads:
93+
for _p0, p1, p2 in quads:
9494
path.quadTo(*p1[:2], *p2[:2])
9595
if vmobject.consider_points_equals(subpath[0], subpath[-1]):
9696
path.close()
@@ -100,7 +100,7 @@ def _convert_vmobject_to_skia_path(self, vmobject: VMobject) -> SkiaPath:
100100
quads = vmobject.gen_cubic_bezier_tuples_from_points(subpath)
101101
start = subpath[0]
102102
path.moveTo(*start[:2])
103-
for p0, p1, p2, p3 in quads:
103+
for _p0, p1, p2, p3 in quads:
104104
path.cubicTo(*p1[:2], *p2[:2], *p3[:2])
105105

106106
if vmobject.consider_points_equals_2d(subpath[0], subpath[-1]):

manim/mobject/graph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,11 @@ def _determine_graph_layout(
469469
return cast(LayoutFunction, layout)(
470470
nx_graph, scale=layout_scale, **layout_config
471471
)
472-
except TypeError:
472+
except TypeError as e:
473473
raise ValueError(
474474
f"The layout '{layout}' is neither a recognized layout, a layout function,"
475475
"nor a vertex placement dictionary.",
476-
)
476+
) from e
477477

478478

479479
class GenericGraph(VMobject, metaclass=ConvertToOpenGL):

manim/mobject/opengl/opengl_point_cloud_mobject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def thin_out(self, factor=5):
7171
for mob in self.family_members_with_points():
7272
num_points = mob.get_num_points()
7373

74-
def thin_func():
74+
def thin_func(num_points=num_points):
7575
return np.arange(0, num_points, factor)
7676

7777
if len(mob.points) == len(mob.rgbas):

manim/mobject/svg/brace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def __init__(
249249
self.brace = Brace(obj, brace_direction, buff, **brace_config)
250250

251251
if isinstance(text, (tuple, list)):
252-
self.label = self.label_constructor(font_size=font_size, *text, **kwargs)
252+
self.label = self.label_constructor(*text, font_size=font_size, **kwargs)
253253
else:
254254
self.label = self.label_constructor(str(text), font_size=font_size)
255255

manim/mobject/text/text_mobject.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,9 @@ def _extract_gradient_tags(self):
14531453
"end_offset": end_offset,
14541454
},
14551455
)
1456-
self.text = re.sub("<gradient[^>]+>(.+?)</gradient>", r"\1", self.text, 0, re.S)
1456+
self.text = re.sub(
1457+
"<gradient[^>]+>(.+?)</gradient>", r"\1", self.text, count=0, flags=re.S
1458+
)
14571459
return gradientmap
14581460

14591461
def _parse_color(self, col):
@@ -1495,7 +1497,9 @@ def _extract_color_tags(self):
14951497
"end_offset": end_offset,
14961498
},
14971499
)
1498-
self.text = re.sub("<color[^>]+>(.+?)</color>", r"\1", self.text, 0, re.S)
1500+
self.text = re.sub(
1501+
"<color[^>]+>(.+?)</color>", r"\1", self.text, count=0, flags=re.S
1502+
)
14991503
return colormap
15001504

15011505
def __repr__(self):

0 commit comments

Comments
 (0)