Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fix Some Warnings from lgtm (#1471)

Naveen M K65d852f33c69
diff --git a/manim/animation/indication.py b/manim/animation/indication.py
index 7bca1477d..a86e3be14 100644
--- a/manim/animation/indication.py
+++ b/manim/animation/indication.py
@@ -45,7 +45,7 @@ __all__ = [
"Wiggle",
]
-
+import typing
from typing import Callable, Type, Union
import numpy as np
@@ -684,7 +684,7 @@ class WiggleOutThenIn(Wiggle):
logger.warning(
"WiggleOutThenIn has been deprecated in favor of Wiggle. Please use Wiggle instead!"
)
- super().__init(*args, **kwargs)
+ super().__init__(*args, **kwargs)
class TurnInsideOut(Transform):
diff --git a/manim/animation/transform.py b/manim/animation/transform.py
index f9690cebf..7a2194e5a 100644
--- a/manim/animation/transform.py
+++ b/manim/animation/transform.py
@@ -26,17 +26,7 @@ __all__ = [
import inspect
import types
-from typing import (
- TYPE_CHECKING,
- Any,
- Callable,
- Dict,
- Iterable,
- List,
- Optional,
- TypeVar,
- Union,
-)
+from typing import TYPE_CHECKING, Any, Callable, Iterable, List, Optional
import numpy as np
@@ -45,7 +35,7 @@ from ..animation.animation import Animation
from ..constants import DEFAULT_POINTWISE_FUNCTION_RUN_TIME, DEGREES, OUT
from ..mobject.mobject import Group, Mobject
from ..mobject.opengl_mobject import OpenGLGroup, OpenGLMobject
-from ..utils.paths import path_along_arc, straight_path
+from ..utils.paths import path_along_arc
from ..utils.rate_functions import smooth, squish_rate_func
if TYPE_CHECKING:
diff --git a/manim/constants.py b/manim/constants.py
index c9daca46d..8622e881b 100644
--- a/manim/constants.py
+++ b/manim/constants.py
@@ -7,6 +7,75 @@ import typing
import numpy as np
from PIL import Image
+__all__ = [
+ "NOT_SETTING_FONT_MSG",
+ "SCENE_NOT_FOUND_MESSAGE",
+ "CHOOSE_NUMBER_MESSAGE",
+ "INVALID_NUMBER_MESSAGE",
+ "NO_SCENE_MESSAGE",
+ "NORMAL",
+ "ITALIC",
+ "OBLIQUE",
+ "BOLD",
+ "THIN",
+ "ULTRALIGHT",
+ "LIGHT",
+ "SEMILIGHT",
+ "BOOK",
+ "MEDIUM",
+ "SEMIBOLD",
+ "ULTRABOLD",
+ "HEAVY",
+ "ULTRAHEAVY",
+ "RESAMPLING_ALGORITHMS",
+ "ORIGIN",
+ "UP",
+ "DOWN",
+ "RIGHT",
+ "LEFT",
+ "IN",
+ "OUT",
+ "X_AXIS",
+ "Y_AXIS",
+ "Z_AXIS",
+ "UL",
+ "UR",
+ "DL",
+ "DR",
+ "START_X",
+ "START_Y",
+ "DEFAULT_DOT_RADIUS",
+ "DEFAULT_SMALL_DOT_RADIUS",
+ "DEFAULT_DASH_LENGTH",
+ "DEFAULT_ARROW_TIP_LENGTH",
+ "SMALL_BUFF",
+ "MED_SMALL_BUFF",
+ "MED_LARGE_BUFF",
+ "LARGE_BUFF",
+ "DEFAULT_MOBJECT_TO_EDGE_BUFFER",
+ "DEFAULT_MOBJECT_TO_MOBJECT_BUFFER",
+ "DEFAULT_POINTWISE_FUNCTION_RUN_TIME",
+ "DEFAULT_WAIT_TIME",
+ "DEFAULT_POINT_DENSITY_2D",
+ "DEFAULT_POINT_DENSITY_1D",
+ "DEFAULT_STROKE_WIDTH",
+ "PI",
+ "TAU",
+ "DEGREES",
+ "FFMPEG_BIN",
+ "GIF_FILE_EXTENSION",
+ "FFMPEG_VERBOSITY_MAP",
+ "VERBOSITY_CHOICES",
+ "WEBGL_RENDERER_INFO",
+ "QUALITIES",
+ "DEFAULT_QUALITY",
+ "DEFAULT_QUALITY_SHORT",
+ "EPILOG",
+ "HELP_OPTIONS",
+ "CONTEXT_SETTINGS",
+ "SHIFT_VALUE",
+ "CTRL_VALUE",
+]
# Messages
NOT_SETTING_FONT_MSG: str = """
You haven't set font.
@@ -26,7 +95,7 @@ NO_SCENE_MESSAGE: str = """
There are no scenes inside that module
"""
-# Cairo and Pango stuff
+# Pango stuff
NORMAL: str = "NORMAL"
ITALIC: str = "ITALIC"
OBLIQUE: str = "OBLIQUE"
diff --git a/manim/mobject/functions.py b/manim/mobject/functions.py
index eed380af8..c39d64d52 100644
--- a/manim/mobject/functions.py
+++ b/manim/mobject/functions.py
@@ -3,7 +3,7 @@
__all__ = ["ParametricFunction", "FunctionGraph"]
-import math
+import numpy as np
from .. import config
from ..constants import *
diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py
index d6320df9b..e79a4f182 100644
--- a/manim/mobject/mobject.py
+++ b/manim/mobject/mobject.py
@@ -35,7 +35,6 @@ from ..utils.paths import straight_path
from ..utils.simple_functions import get_parameters
from ..utils.space_ops import (
angle_between_vectors,
- angle_of_vector,
normalize,
rotation_matrix,
rotation_matrix_transpose,
@@ -1508,7 +1507,6 @@ class Mobject(Container):
def replace(self, mobject, dim_to_match=0, stretch=False):
if not mobject.get_num_points() and not mobject.submobjects:
raise Warning("Attempting to replace mobject with no points")
- return self
if stretch:
self.stretch_to_fit_width(mobject.width)
self.stretch_to_fit_height(mobject.height)
diff --git a/manim/mobject/numbers.py b/manim/mobject/numbers.py
index 9dc97b533..073f58fbc 100644
--- a/manim/mobject/numbers.py
+++ b/manim/mobject/numbers.py
@@ -4,6 +4,8 @@ __all__ = ["DecimalNumber", "Integer", "Variable"]
import uuid
+import numpy as np
+
from ..constants import *
from ..mobject.svg.tex_mobject import MathTex, SingleStringMathTex
from ..mobject.types.vectorized_mobject import VMobject
diff --git a/manim/mobject/opengl_geometry.py b/manim/mobject/opengl_geometry.py
index 8f47ef6c2..493207079 100644
--- a/manim/mobject/opengl_geometry.py
+++ b/manim/mobject/opengl_geometry.py
@@ -211,7 +211,7 @@ class OpenGLArc(OpenGLTipableVMobject):
self.n_components = n_components
self.anchors_span_full_range = anchors_span_full_range
self.arc_center = arc_center
- OpenGLVMobject.__init__(self, **kwargs)
+ super().__init__(self, **kwargs)
def init_points(self):
self.set_points(
diff --git a/manim/mobject/opengl_mobject.py b/manim/mobject/opengl_mobject.py
index c45840b36..4a5ab9f63 100644
--- a/manim/mobject/opengl_mobject.py
+++ b/manim/mobject/opengl_mobject.py
@@ -3,7 +3,6 @@ import itertools as it
import random
import sys
from functools import wraps
-from typing import List, Union
import moderngl
import numpy as np
diff --git a/manim/mobject/polyhedra.py b/manim/mobject/polyhedra.py
index 1abaaade1..837964485 100644
--- a/manim/mobject/polyhedra.py
+++ b/manim/mobject/polyhedra.py
@@ -1,15 +1,13 @@
"""General polyhedral class and platonic solids."""
-from copy import copy
-from typing import TYPE_CHECKING, Dict, Hashable, List, Tuple, Union
+from typing import TYPE_CHECKING, Dict, List, Tuple, Union
import numpy as np
from .geometry import Polygon
from .graph import Graph
-from .mobject_update_utils import always
from .three_dimensions import Dot3D
-from .types.vectorized_mobject import VGroup, VMobject
+from .types.vectorized_mobject import VGroup
if TYPE_CHECKING:
from .mobject import Mobject
diff --git a/manim/mobject/svg/code_mobject.py b/manim/mobject/svg/code_mobject.py
index 64a753e55..c9646e094 100644
--- a/manim/mobject/svg/code_mobject.py
+++ b/manim/mobject/svg/code_mobject.py
@@ -10,6 +10,7 @@ import html
import os
import re
+import numpy as np
from pygments import highlight
from pygments.formatters.html import HtmlFormatter
from pygments.lexers import get_lexer_by_name, guess_lexer_for_filename
diff --git a/manim/mobject/svg/opengl_text_mobject.py b/manim/mobject/svg/opengl_text_mobject.py
index ed982dc01..1b795252f 100644
--- a/manim/mobject/svg/opengl_text_mobject.py
+++ b/manim/mobject/svg/opengl_text_mobject.py
@@ -49,14 +49,10 @@ import copy
import hashlib
import os
import re
-import sys
import typing
from contextlib import contextmanager
from pathlib import Path
-from typing import Dict
-from xml.sax.saxutils import escape
-import cairo
import manimpango
from manimpango import MarkupUtils, PangoUtils, TextSetting
@@ -138,7 +134,6 @@ class OpenGLParagraph(OpenGLVGroup):
def __init__(self, *text, line_spacing=-1, alignment=None, **config):
self.line_spacing = line_spacing
self.alignment = alignment
- OpenGLVGroup.__init__(self, **config)
lines_str = "\n".join(list(text))
self.lines_text = OpenGLText(lines_str, line_spacing=line_spacing, **config)
@@ -400,11 +395,11 @@ class OpenGLText(OpenGLSVGMobject):
font: str = "",
slant: str = NORMAL,
weight: str = NORMAL,
- t2c: Dict[str, str] = None,
- t2f: Dict[str, str] = None,
- t2g: Dict[str, tuple] = None,
- t2s: Dict[str, str] = None,
- t2w: Dict[str, str] = None,
+ t2c: typing.Dict[str, str] = None,
+ t2f: typing.Dict[str, str] = None,
+ t2g: typing.Dict[str, tuple] = None,
+ t2s: typing.Dict[str, str] = None,
+ t2w: typing.Dict[str, str] = None,
gradient: tuple = None,
tab_width: int = 4,
# Mobject
diff --git a/manim/mobject/svg/svg_mobject.py b/manim/mobject/svg/svg_mobject.py
index dff423acd..9973a079a 100644
--- a/manim/mobject/svg/svg_mobject.py
+++ b/manim/mobject/svg/svg_mobject.py
@@ -13,9 +13,9 @@ from typing import Dict, List
from xml.dom.minidom import Element as MinidomElement
from xml.dom.minidom import parse as minidom_parse
-from manim import logger
+import numpy as np
-from ... import config
+from ... import config, logger
from ...constants import *
from ...mobject.geometry import Circle, Line, Rectangle, RoundedRectangle
from ...mobject.opengl_geometry import OpenGLRectangle, OpenGLRoundedRectangle
diff --git a/manim/mobject/svg/svg_path.py b/manim/mobject/svg/svg_path.py
index cd7871299..289847c5f 100644
--- a/manim/mobject/svg/svg_path.py
+++ b/manim/mobject/svg/svg_path.py
@@ -7,6 +7,8 @@ __all__ = ["SVGPathMobject", "string_to_numbers", "VMobjectFromSVGPathstring"]
import re
from typing import List
+import numpy as np
+
from manim import logger
from ... import config
diff --git a/manim/mobject/svg/text_mobject.py b/manim/mobject/svg/text_mobject.py
index f4c31489d..eda7ed701 100644
--- a/manim/mobject/svg/text_mobject.py
+++ b/manim/mobject/svg/text_mobject.py
@@ -55,6 +55,7 @@ from pathlib import Path
from typing import Dict
import manimpango
+import numpy as np
from manimpango import MarkupUtils, PangoUtils, TextSetting
from ... import config, logger
diff --git a/manim/mobject/types/image_mobject.py b/manim/mobject/types/image_mobject.py
index d60437085..28bdfbca3 100644
--- a/manim/mobject/types/image_mobject.py
+++ b/manim/mobject/types/image_mobject.py
@@ -45,7 +45,7 @@ class AbstractImageMobject(Mobject):
def get_pixel_array(self):
raise NotImplementedError()
- def set_color(self):
+ def set_color(self, color, alpha=None, family=True):
# Likely to be implemented in subclasses, but no obligation
pass
diff --git a/manim/mobject/types/opengl_vectorized_mobject.py b/manim/mobject/types/opengl_vectorized_mobject.py
index df9a07af6..e6eb5250a 100644
--- a/manim/mobject/types/opengl_vectorized_mobject.py
+++ b/manim/mobject/types/opengl_vectorized_mobject.py
@@ -1,5 +1,6 @@
import itertools as it
import operator as op
+import typing
from functools import reduce, wraps
from typing import Optional
diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py
index 7bc691c52..ae0a9d1b2 100644
--- a/manim/mobject/types/vectorized_mobject.py
+++ b/manim/mobject/types/vectorized_mobject.py
@@ -13,7 +13,8 @@ __all__ = [
import itertools as it
import sys
-from typing import Iterable, Optional, Sequence, Union
+import typing
+from typing import Optional, Sequence, Union
import colour
import numpy as np
@@ -430,14 +431,14 @@ class VMobject(Mobject):
offset = np.dot(bases, direction)
return (c - offset, c + offset)
- def color_using_background_image(self, background_image: Union[Image.Image, str]):
+ def color_using_background_image(self, background_image: Union[Image, str]):
self.background_image = background_image
self.set_color(WHITE)
for submob in self.submobjects:
submob.color_using_background_image(background_image)
return self
- def get_background_image(self) -> Union[Image.Image, str]:
+ def get_background_image(self) -> Union[Image, str]:
return self.background_image
def match_background_image(self, vmobject):
diff --git a/manim/scene/graph_scene.py b/manim/scene/graph_scene.py
index d681e237c..75763d6f8 100644
--- a/manim/scene/graph_scene.py
+++ b/manim/scene/graph_scene.py
@@ -45,9 +45,10 @@ Examples
__all__ = ["GraphScene"]
-
import itertools as it
+import numpy as np
+
from .. import config, logger
from ..animation.creation import Create, DrawBorderThenFill, Write
from ..animation.transform import Transform
diff --git a/manim/scene/scene.py b/manim/scene/scene.py
index 995837675..8f9caabaf 100644
--- a/manim/scene/scene.py
+++ b/manim/scene/scene.py
@@ -8,8 +8,6 @@ import copy
import inspect
import platform
import random
-import string
-import sys
import threading
import types
import warnings
@@ -25,8 +23,7 @@ from ..animation.animation import Animation, Wait, prepare_animation
from ..camera.camera import Camera
from ..constants import *
from ..container import Container
-from ..mobject.mobject import Mobject, _AnimationBuilder
-from ..mobject.opengl_mobject import OpenGLMobject, OpenGLPoint
+from ..mobject.opengl_mobject import OpenGLPoint
from ..renderer.cairo_renderer import CairoRenderer
from ..renderer.shader import Mesh
from ..utils import opengl, space_ops
diff --git a/manim/utils/space_ops.py b/manim/utils/space_ops.py
index e2f077c28..60a9cb644 100644
--- a/manim/utils/space_ops.py
+++ b/manim/utils/space_ops.py
@@ -42,7 +42,6 @@ from mapbox_earcut import triangulate_float32 as earcut
from .. import config
from ..constants import DOWN, OUT, PI, RIGHT, TAU
from ..utils.iterables import adjacent_pairs
-from ..utils.simple_functions import fdiv
def get_norm(vect):