Skip to content

Commit 5e4afaf

Browse files
Merge branch 'main' of https://github.com/ManimCommunity/manim into improve-matmul
2 parents 7b22e8a + 2075f82 commit 5e4afaf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+327
-206
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
- id: python-check-blanket-noqa
1919
name: Precision flake ignores
2020
- repo: https://github.com/astral-sh/ruff-pre-commit
21-
rev: v0.5.2
21+
rev: v0.5.4
2222
hooks:
2323
- id: ruff
2424
name: ruff lint
@@ -32,16 +32,13 @@ repos:
3232
- id: flake8
3333
additional_dependencies:
3434
[
35-
flake8-bugbear==21.4.3,
36-
flake8-builtins==1.5.3,
37-
flake8-comprehensions>=3.6.1,
3835
flake8-docstrings==1.6.0,
3936
flake8-pytest-style==1.5.0,
4037
flake8-rst-docstrings==0.2.3,
4138
flake8-simplify==0.14.1,
4239
]
4340
- repo: https://github.com/pre-commit/mirrors-mypy
44-
rev: v1.10.1
41+
rev: v1.11.0
4542
hooks:
4643
- id: mypy
4744
additional_dependencies:

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# -- Project information -----------------------------------------------------
2727

2828
project = "Manim"
29-
copyright = f"2020-{datetime.now().year}, The Manim Community Dev Team"
29+
copyright = f"2020-{datetime.now().year}, The Manim Community Dev Team" # noqa: A001
3030
author = "The Manim Community Dev Team"
3131

3232

@@ -63,7 +63,7 @@
6363
alias_name: f"~manim.{module}.{alias_name}"
6464
for module, module_dict in ALIAS_DOCS_DICT.items()
6565
for category_dict in module_dict.values()
66-
for alias_name in category_dict.keys()
66+
for alias_name in category_dict
6767
}
6868
autoclass_content = "both"
6969

manim/_config/utils.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -643,21 +643,18 @@ 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)
657-
if plugins == "":
658-
plugins = []
659-
else:
660-
plugins = plugins.split(",")
657+
plugins = [] if plugins == "" else plugins.split(",")
661658
self.plugins = plugins
662659
# the next two must be set AFTER digesting pixel_width and pixel_height
663660
self["frame_height"] = parser["CLI"].getfloat("frame_height", 8.0)
@@ -674,7 +671,7 @@ def digest_parser(self, parser: configparser.ConfigParser) -> Self:
674671

675672
val = parser["CLI"].get("progress_bar")
676673
if val:
677-
setattr(self, "progress_bar", val)
674+
self.progress_bar = val
678675

679676
val = parser["ffmpeg"].get("loglevel")
680677
if val:
@@ -684,11 +681,11 @@ def digest_parser(self, parser: configparser.ConfigParser) -> Self:
684681
val = parser["jupyter"].getboolean("media_embed")
685682
except ValueError:
686683
val = None
687-
setattr(self, "media_embed", val)
684+
self.media_embed = val
688685

689686
val = parser["jupyter"].get("media_width")
690687
if val:
691-
setattr(self, "media_width", val)
688+
self.media_width = val
692689

693690
val = parser["CLI"].get("quality", fallback="", raw=True)
694691
if val:
@@ -839,15 +836,12 @@ def digest_args(self, args: argparse.Namespace) -> Self:
839836
if args.tex_template:
840837
self.tex_template = TexTemplate.from_file(args.tex_template)
841838

842-
if (
843-
self.renderer == RendererType.OPENGL
844-
and getattr(args, "write_to_movie") is None
845-
):
839+
if self.renderer == RendererType.OPENGL and args.write_to_movie is None:
846840
# --write_to_movie was not passed on the command line, so don't generate video.
847841
self["write_to_movie"] = False
848842

849843
# Handle --gui_location flag.
850-
if getattr(args, "gui_location") is not None:
844+
if args.gui_location is not None:
851845
self.gui_location = args.gui_location
852846

853847
return self

manim/animation/animation.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from collections.abc import Iterable, Sequence
1818
from copy import deepcopy
19+
from functools import partialmethod
1920
from typing import TYPE_CHECKING, Callable
2021

2122
from typing_extensions import Self
@@ -479,6 +480,52 @@ def is_introducer(self) -> bool:
479480
"""
480481
return self.introducer
481482

483+
@classmethod
484+
def __init_subclass__(cls, **kwargs) -> None:
485+
super().__init_subclass__(**kwargs)
486+
487+
cls._original__init__ = cls.__init__
488+
489+
@classmethod
490+
def set_default(cls, **kwargs) -> None:
491+
"""Sets the default values of keyword arguments.
492+
493+
If this method is called without any additional keyword
494+
arguments, the original default values of the initialization
495+
method of this class are restored.
496+
497+
Parameters
498+
----------
499+
500+
kwargs
501+
Passing any keyword argument will update the default
502+
values of the keyword arguments of the initialization
503+
function of this class.
504+
505+
Examples
506+
--------
507+
508+
.. manim:: ChangeDefaultAnimation
509+
510+
class ChangeDefaultAnimation(Scene):
511+
def construct(self):
512+
Rotate.set_default(run_time=2, rate_func=rate_functions.linear)
513+
Indicate.set_default(color=None)
514+
515+
S = Square(color=BLUE, fill_color=BLUE, fill_opacity=0.25)
516+
self.add(S)
517+
self.play(Rotate(S, PI))
518+
self.play(Indicate(S))
519+
520+
Rotate.set_default()
521+
Indicate.set_default()
522+
523+
"""
524+
if kwargs:
525+
cls.__init__ = partialmethod(cls.__init__, **kwargs)
526+
else:
527+
cls.__init__ = cls._original__init__
528+
482529

483530
def prepare_animation(
484531
anim: Animation | mobject._AnimationBuilder,

manim/animation/creation.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,7 @@ def _set_default_config_from_length(
351351
) -> tuple[float, float]:
352352
length = len(vmobject.family_members_with_points())
353353
if run_time is None:
354-
if length < 15:
355-
run_time = 1
356-
else:
357-
run_time = 2
354+
run_time = 1 if length < 15 else 2
358355
if lag_ratio is None:
359356
lag_ratio = min(4.0 / max(1.0, length), 0.2)
360357
return run_time, lag_ratio

manim/animation/fading.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ def __init__(
5757
) -> None:
5858
if not mobjects:
5959
raise ValueError("At least one mobject must be passed.")
60-
if len(mobjects) == 1:
61-
mobject = mobjects[0]
62-
else:
63-
mobject = Group(*mobjects)
60+
mobject = mobjects[0] if len(mobjects) == 1 else Group(*mobjects)
6461

6562
self.point_target = False
6663
if shift is None:

manim/animation/specialized.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ def __init__(
7070
anims = []
7171

7272
# 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.
73-
if mobject.fill_opacity:
74-
fill_o = True
75-
else:
76-
fill_o = False
73+
fill_o = bool(mobject.fill_opacity)
7774

7875
for _ in range(self.n_mobs):
7976
mob = mobject.copy()

manim/cli/cfg/group.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from __future__ import annotations
1010

11+
import contextlib
1112
from ast import literal_eval
1213
from pathlib import Path
1314

@@ -51,10 +52,8 @@ def value_from_string(value: str) -> str | int | bool:
5152
Union[:class:`str`, :class:`int`, :class:`bool`]
5253
Returns the literal of appropriate datatype.
5354
"""
54-
try:
55+
with contextlib.suppress(SyntaxError, ValueError):
5556
value = literal_eval(value)
56-
except (SyntaxError, ValueError):
57-
pass
5857
return value
5958

6059

@@ -197,7 +196,7 @@ def write(level: str = None, openfile: bool = False) -> None:
197196
"""Not enough values in input.
198197
You may have added a new entry to default.cfg, in which case you will have to
199198
modify write_cfg_subcmd_input to account for it.""",
200-
)
199+
) from None
201200
if temp:
202201
while temp and not _is_expected_datatype(
203202
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

0 commit comments

Comments
 (0)