pre-commit change to ruff (#3779)

* pre-commit change to ruff

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fixes

* astral-sh ruff bump

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
adeshpande 2024-05-22 12:03:23 -04:00 committed by GitHub
commit 24025b60d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 113 additions and 88 deletions

View file

@ -34,16 +34,11 @@ repos:
hooks:
- id: python-check-blanket-noqa
name: 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.4
hooks:
- 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/flake8
rev: 7.0.0
hooks:

View file

@ -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))

View file

@ -68,7 +68,6 @@ def tempconfig(temp: ManimConfig | dict[str, Any]) -> Generator[None, None, None
8.0
>>> with tempconfig({"frame_height": 100.0}):
... print(config["frame_height"])
...
100.0
>>> config["frame_height"]
8.0

View file

@ -35,15 +35,18 @@ def parse_cli_ctx(parser: configparser.SectionProxy) -> Context:
theme = parser["theme"] if parser["theme"] else None
if 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(

View file

@ -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, Create

View file

@ -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:

View file

@ -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 labels
ax.add_coordinates(x_labels) # only x labels
You 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)
"""

View file

@ -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])
"""

View file

@ -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 equivalent
max_y_1 = sample.get_top()[1]

View file

@ -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(

View file

@ -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 constructed
VGroup(Triangle, Square)
>>> vg # not modified
>>> vg # not modified
VGroup(Triangle)
>>> vg += square; vg # modifies vg
>>> vg += square
>>> vg # modifies vg
VGroup(Triangle, Square)
>>> vg.remove(triangle)
VGroup(Square)
>>> vg - square; # a new VGroup is constructed
>>> vg - square # a new VGroup is constructed
VGroup()
>>> vg # not modified
>>> vg # not modified
VGroup(Square)
>>> vg -= square; vg # modifies vg
>>> vg -= square
>>> vg # modifies vg
VGroup()
.. 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])

View file

@ -1555,8 +1555,7 @@ class Scene:
# second option: within the call to Scene.play
self.play(
Transform(square, circle),
subcaption="The square transforms."
Transform(square, circle), subcaption="The square transforms."
)
"""

View file

@ -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(

View file

@ -22,6 +22,7 @@ List of Color Constants
.. automanimcolormodule:: manim.utils.color.X11
"""
from .core import ManimColor
ALICEBLUE = ManimColor("#F0F8FF")

View file

@ -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: ignore

View file

@ -105,10 +105,12 @@ def deprecated(
from manim.utils.deprecation import deprecated
@deprecated
def foo(**kwargs):
pass
@deprecated
class 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}

View file

@ -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_CHECKING

View file

@ -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.0

View file

@ -22,9 +22,7 @@ def test_special_tags_markup():
success = True
except 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():

View file

@ -22,9 +22,7 @@ def test_special_tags_markup(using_opengl_renderer):
success = True
except 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):

View file

@ -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"

View file

@ -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"