Skip to content
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

Replace Pyupgrade with Ruff rule #3795

Merged
merged 6 commits into from
Jun 5, 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
6 changes: 0 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ repos:
- id: end-of-file-fixer
- id: check-toml
name: Validate Poetry
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
name: Update code to new python versions
args: [--py39-plus]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion manim/mobject/geometry/boolean_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _convert_skia_path_to_vmobject(self, path: SkiaPath) -> VMobject:
n1, n2 = self._convert_2d_to_3d_array(points)
vmobject.add_quadratic_bezier_curve_to(n1, n2)
else:
raise Exception("Unsupported: %s" % path_verb)
raise Exception(f"Unsupported: {path_verb}")
return vmobject


Expand Down
2 changes: 1 addition & 1 deletion manim/mobject/graphing/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def get_custom_labels(
tex_labels = [
Integer(
self.base,
unit="^{%s}" % (f"{self.inverse_function(i):.{unit_decimal_places}f}"),
unit="^{%s}" % (f"{self.inverse_function(i):.{unit_decimal_places}f}"), # noqa: UP031
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unit="^{%s}" % (f"{self.inverse_function(i):.{unit_decimal_places}f}"), # noqa: UP031
unit="^{:.{prec}f}".format(self.inverse_function(i), prec=unit_decimal_places)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of hard to understand, and also causes the tests to fail.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say the original version is even more confusing. It was probably failing because of the missing f" prefix

**base_config,
)
for i in val_range
Expand Down
7 changes: 1 addition & 6 deletions manim/mobject/opengl/opengl_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2659,12 +2659,7 @@ def set_color_by_xyz_func(
glsl_snippet = glsl_snippet.replace(char, "point." + char)
rgb_list = get_colormap_list(colormap)
self.set_color_by_code(
"color.rgb = float_to_color({}, {}, {}, {});".format(
glsl_snippet,
float(min_value),
float(max_value),
get_colormap_code(rgb_list),
),
f"color.rgb = float_to_color({glsl_snippet}, {float(min_value)}, {float(max_value)}, {get_colormap_code(rgb_list)});",
)
return self

Expand Down
4 changes: 2 additions & 2 deletions manim/mobject/text/tex_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ def _modify_special_strings(self, tex):
tex = self._remove_stray_braces(tex)

for context in ["array"]:
begin_in = ("\\begin{%s}" % context) in tex
end_in = ("\\end{%s}" % context) in tex
begin_in = ("\\begin{%s}" % context) in tex # noqa: UP031
end_in = ("\\end{%s}" % context) in tex # noqa: UP031
if begin_in ^ end_in:
# Just turn this into a blank string,
# which means caller should leave a
Expand Down
2 changes: 1 addition & 1 deletion manim/mobject/types/vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -2308,7 +2308,7 @@ def remove(self, key: Hashable) -> Self:
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))
raise KeyError(f"The given key '{key!s}' is not present in the VDict")
super().remove(self.submob_dict[key])
del self.submob_dict[key]
return self
Expand Down
7 changes: 3 additions & 4 deletions manim/scene/vector_space_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def get_vector_label(
"""
if not isinstance(label, MathTex):
if len(label) == 1:
label = "\\vec{\\textbf{%s}}" % label
label = "\\vec{\\textbf{%s}}" % label # noqa: UP031
label = MathTex(label)
if color is None:
color = vector.get_color()
Expand Down Expand Up @@ -904,9 +904,8 @@ def add_transformable_label(
if new_label:
label_mob.target_text = new_label
else:
label_mob.target_text = "{}({})".format(
transformation_name,
label_mob.get_tex_string(),
label_mob.target_text = (
f"{transformation_name}({label_mob.get_tex_string()})"
)
label_mob.vector = vector
label_mob.kwargs = kwargs
Expand Down
2 changes: 1 addition & 1 deletion manim/utils/docbuild/autocolor_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def run(self) -> list[nodes.Element]:
return [
nodes.error(
None,
nodes.paragraph(text="Failed to import module '%s'" % module_name),
nodes.paragraph(text=f"Failed to import module '{module_name}'"),
)
]

Expand Down
2 changes: 1 addition & 1 deletion manim/utils/docbuild/manim_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def _write_rendering_stats(scene_name: str, run_time: str, file_name: str) -> No
[
re.sub(r"^(reference\/)|(manim\.)", "", file_name),
scene_name,
"%.3f" % run_time,
f"{run_time:.3f}",
],
)

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ select = [
"E",
"F",
"I",
"UP",
]

ignore = [
Expand Down
Loading