Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Ignore fewer flake8 errors (#1960)

Christian Clauss97109e75b43c
diff --git a/.flake8 b/.flake8
index a3875c056..046c8cc19 100644
--- a/.flake8
+++ b/.flake8
@@ -2,25 +2,26 @@
# Exclude the grpc generated code
exclude = ./.*,manim/grpc/gen/*
max-complexity = 35
-max-line-length = 250
- #Black Compatibility
-extend-ignore = E203, E266,
- #Style Changes
-
- #Temp
- F841, B007,
- #I believe these are unfixable
- B006
- #Code Changes - Remove later -remove from .pre-commit-config.yaml
+max-line-length = 211
+statistics = True
+ # Black Compatibility
+extend-ignore = E203, W503,
- F405, F403, F401, B008, B009, B010, E731
- #docstring Formatting - Remove Later -remove from .pre-commit-config.yaml
+ # Unused imports, wildcard imports, and unused variables
+ F401, F403, F405, F841,
- RST304, D400, D401, D205, D105, D103, RST210, RST303, D102, D102, D107, RST212, D200, D100, D101,
- D412, D202, RST305, RST301, D301, RST213, D104, RST201, RST215, RST203, D104, D209, RST205, D402,
- D210, RST202
+ # Plug-in: flake8-builtins
+ A001, A002, A003,
- #Issue #1148 needs to be closed before removal -remove from .pre-commit-config.yaml
- A003,
- #Issue #1149 needs to be closed before removal -remove from .pre-commit-config.yaml
- W605,
+ # Plug-in: flake8-bugbear
+ B006, B007, B008, B009, B010, B011, B015,
+
+ # Plug-in: flake8-docstrings
+ D100, D101, D102, D103, D104, D105, D106, D107,
+ D200, D202, D204, D205, D209,
+ D301,
+ D400, D401, D402, D403, D412, D414,
+
+ # Plug-in: flake8-rst-docstrings
+ RST201, RST203, RST205, RST210, RST212, RST213, RST215,
+ RST301, RST303, RST304,
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 0a37b2d15..71585fe9a 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -29,6 +29,7 @@ repos:
rev: 3.9.2
hooks:
- id: flake8
+ additional_dependencies: [flake8-builtins==1.5.3, flake8-bugbear==21.4.3, flake8-docstrings==1.6.0, flake8-rst-docstrings==0.2.3]
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
diff --git a/manim/camera/camera.py b/manim/camera/camera.py
index 88dfa18cb..0ec36833e 100644
--- a/manim/camera/camera.py
+++ b/manim/camera/camera.py
@@ -732,10 +732,8 @@ class Camera:
ctx.set_line_width(
width
* self.cairo_line_width_multiple
- *
- # This ensures lines have constant width
- # as you zoom in on them.
- (self.frame_width / self.frame_width)
+ # This ensures lines have constant width as you zoom in on them.
+ * (self.frame_width / self.frame_width)
)
ctx.stroke_preserve()
return self
diff --git a/manim/mobject/coordinate_systems.py b/manim/mobject/coordinate_systems.py
index 7f89823ac..19673b927 100644
--- a/manim/mobject/coordinate_systems.py
+++ b/manim/mobject/coordinate_systems.py
@@ -1716,7 +1716,9 @@ class PolarPlane(Axes):
- ``None``: Decimal labels in the interval :math:`\left[0, 1\right]`.
azimuth_compact_fraction
- If the ``azimuth_units`` choice has fractional labels, choose whether to combine the constant in a compact form :math:`\tfrac{xu}{y}` as opposed to :math:`\tfrac{x}{y}u`, where :math:`u` is the constant.
+ If the ``azimuth_units`` choice has fractional labels, choose whether to
+ combine the constant in a compact form :math:`\tfrac{xu}{y}` as opposed to
+ :math:`\tfrac{x}{y}u`, where :math:`u` is the constant.
azimuth_offset
The angle offset of the azimuth, expressed in radians.
diff --git a/manim/mobject/mobject.py b/manim/mobject/mobject.py
index 53c0433d7..8e52a92e6 100644
--- a/manim/mobject/mobject.py
+++ b/manim/mobject/mobject.py
@@ -304,8 +304,12 @@ class Mobject:
.. warning::
``.animate``
- will interpolate the :class:`~.Mobject` between its points prior to ``.animate`` and its points after applying ``.animate`` to it. This may result in unexpected behavior when attempting to interpolate along paths, or rotations.
- If you want animations to consider the points between, consider using :class:`~.ValueTracker` with updaters instead.
+ will interpolate the :class:`~.Mobject` between its points prior to
+ ``.animate`` and its points after applying ``.animate`` to it. This may
+ result in unexpected behavior when attempting to interpolate along paths,
+ or rotations.
+ If you want animations to consider the points between, consider using
+ :class:`~.ValueTracker` with updaters instead.
"""
return _AnimationBuilder(self)
@@ -332,14 +336,16 @@ class Mobject:
def init_colors(self):
"""Initializes the colors.
- Gets called upon creation. This is an empty method that can be implemented by subclasses.
+ Gets called upon creation. This is an empty method that can be implemented by
+ subclasses.
"""
pass
def generate_points(self):
"""Initializes :attr:`points` and therefore the shape.
- Gets called upon creation. This is an empty method that can be implemented by subclasses.
+ Gets called upon creation. This is an empty method that can be implemented by
+ subclasses.
"""
pass
@@ -438,7 +444,8 @@ class Mobject:
def add_to_back(self, *mobjects: "Mobject") -> "Mobject":
"""Add all passed mobjects to the back of the submobjects.
- If :attr:`submobjects` already contains the given mobjects, they just get moved to the back instead.
+ If :attr:`submobjects` already contains the given mobjects, they just get moved
+ to the back instead.
Parameters
----------
@@ -592,7 +599,8 @@ class Mobject:
def getter(self):
warnings.warn(
- "This method is not guaranteed to stay around. Please prefer getting the attribute normally.",
+ "This method is not guaranteed to stay around. Please prefer "
+ "getting the attribute normally.",
DeprecationWarning,
stacklevel=2,
)
@@ -608,7 +616,8 @@ class Mobject:
def setter(self, value):
warnings.warn(
- "This method is not guaranteed to stay around. Please prefer setting the attribute normally or with Mobject.set().",
+ "This method is not guaranteed to stay around. Please prefer "
+ "setting the attribute normally or with Mobject.set().",
DeprecationWarning,
stacklevel=2,
)
@@ -740,13 +749,15 @@ class Mobject:
self.get_image(camera=camera).show()
def save_image(self, name=None):
- """Saves an image of only this :class:`Mobject` at its position to a png file."""
+ """Saves an image of only this :class:`Mobject` at its position to a png
+ file."""
self.get_image().save(
Path(config.get_dir("video_dir")).joinpath((name or str(self)) + ".png")
)
def copy(self: T) -> T:
- """Create and return an identical copy of the :class:`Mobject` including all :attr:`submobjects`.
+ """Create and return an identical copy of the :class:`Mobject` including all
+ :attr:`submobjects`.
Returns
-------
@@ -777,7 +788,8 @@ class Mobject:
Parameters
----------
dt
- The parameter ``dt`` to pass to the update functions. Usually this is the time in seconds since the last call of ``update``.
+ The parameter ``dt`` to pass to the update functions. Usually this is the
+ time in seconds since the last call of ``update``.
recursive
Whether to recursively update all submobjects.
@@ -829,7 +841,8 @@ class Mobject:
Returns
-------
class:`bool`
- ``True`` if at least one updater uses the ``dt`` parameter, ``False`` otherwise.
+ ``True`` if at least one updater uses the ``dt`` parameter, ``False``
+ otherwise.
See Also
--------
@@ -868,18 +881,24 @@ class Mobject:
) -> "Mobject":
"""Add an update function to this mobject.
- Update functions, or updaters in short, are functions that are applied to the Mobject in every frame.
+ Update functions, or updaters in short, are functions that are applied to the
+ Mobject in every frame.
Parameters
----------
update_function
The update function to be added.
- Whenever :meth:`update` is called, this update function gets called using ``self`` as the first parameter.
- The updater can have a second parameter ``dt``. If it uses this parameter, it gets called using a second value ``dt``, usually representing the time in seconds since the last call of :meth:`update`.
+ Whenever :meth:`update` is called, this update function gets called using
+ ``self`` as the first parameter.
+ The updater can have a second parameter ``dt``. If it uses this parameter,
+ it gets called using a second value ``dt``, usually representing the time
+ in seconds since the last call of :meth:`update`.
index
- The index at which the new updater should be added in ``self.updaters``. In case ``index`` is ``None`` the updater will be added at the end.
+ The index at which the new updater should be added in ``self.updaters``.
+ In case ``index`` is ``None`` the updater will be added at the end.
call_updater
- Whether or not to call the updater initially. If ``True``, the updater will be called using ``dt=0``.
+ Whether or not to call the updater initially. If ``True``, the updater will
+ be called using ``dt=0``.
Returns
-------
@@ -997,7 +1016,8 @@ class Mobject:
Note
----
- All updaters from submobjects are removed, but only updaters of the given mobject are matched, not those of it's submobjects.
+ All updaters from submobjects are removed, but only updaters of the given
+ mobject are matched, not those of it's submobjects.
See also
--------
@@ -1072,7 +1092,8 @@ class Mobject:
Parameters
----------
func
- The function to apply to each mobject. ``func`` gets passed the respective (sub)mobject as parameter.
+ The function to apply to each mobject. ``func`` gets passed the respective
+ (sub)mobject as parameter.
Returns
-------
@@ -1093,7 +1114,8 @@ class Mobject:
Parameters
----------
vectors
- Vectors to shift by. If multiple vectors are given, they are added together.
+ Vectors to shift by. If multiple vectors are given, they are added
+ together.
Returns
-------
@@ -1130,10 +1152,11 @@ class Mobject:
----------
scale_factor
The scaling factor :math:`\alpha`. If :math:`0 < |\alpha| < 1`, the mobject
- will shrink, and for :math:`|\alpha| > 1` it will grow. Furthermore, if :math:`\alpha < 0`,
- the mobject is also flipped.
+ will shrink, and for :math:`|\alpha| > 1` it will grow. Furthermore,
+ if :math:`\alpha < 0`, the mobject is also flipped.
kwargs
- Additional keyword arguments passed to :meth:`apply_points_function_about_point`.
+ Additional keyword arguments passed to
+ :meth:`apply_points_function_about_point`.
Returns
-------
@@ -2415,7 +2438,10 @@ class Mobject:
def sort(self, point_to_num_func=lambda p: p[0], submob_func=None):
"""Sorts the list of :attr:`submobjects` by a function defined by ``submob_func``."""
if submob_func is None:
- submob_func = lambda m: point_to_num_func(m.get_center())
+
+ def submob_func(m):
+ return point_to_num_func(m.get_center())
+
self.submobjects.sort(key=submob_func)
return self
diff --git a/manim/mobject/svg/svg_path.py b/manim/mobject/svg/svg_path.py
index 2d6f8ac4e..4a871a9ba 100644
--- a/manim/mobject/svg/svg_path.py
+++ b/manim/mobject/svg/svg_path.py
@@ -105,7 +105,7 @@ def elliptical_arc_to_cubic_bezier(x1, y1, rx, ry, phi, fA, fS, x2, y2):
See: http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
"""
- ## Out of range parameters
+ # Out of range parameters
# See: https://www.w3.org/TR/SVG11/implnote.html#ArcOutOfRangeParameters
# If rx or ry are 0 then this arc is treated as a
# straight line segment (a "lineto") joining the endpoints.
diff --git a/manim/mobject/types/image_mobject.py b/manim/mobject/types/image_mobject.py
index 2afa1630f..0a4957ebf 100644
--- a/manim/mobject/types/image_mobject.py
+++ b/manim/mobject/types/image_mobject.py
@@ -26,8 +26,11 @@ class AbstractImageMobject(Mobject):
Parameters
----------
scale_to_resolution : :class:`int`
- At this resolution the image is placed pixel by pixel onto the screen, so it will look the sharpest and best.
- This is a custom parameter of ImageMobject so that rendering a scene with e.g. the ``--quality low`` or ``--quality medium`` flag for faster rendering won't effect the position of the image on the screen.
+ At this resolution the image is placed pixel by pixel onto the screen, so it
+ will look the sharpest and best.
+ This is a custom parameter of ImageMobject so that rendering a scene with
+ e.g. the ``--quality low`` or ``--quality medium`` flag for faster rendering
+ won't effect the position of the image on the screen.
"""
def __init__(
@@ -51,12 +54,16 @@ class AbstractImageMobject(Mobject):
def set_resampling_algorithm(self, resampling_algorithm):
"""
- Sets the interpolation method for upscaling the image. By default the image is interpolated using bicubic algorithm. This method lets you change it.
- Interpolation is done internally using Pillow, and the function besides the string constants describing the algorithm accepts the Pillow integer constants.
+ Sets the interpolation method for upscaling the image. By default the image is
+ interpolated using bicubic algorithm. This method lets you change it.
+ Interpolation is done internally using Pillow, and the function besides the
+ string constants describing the algorithm accepts the Pillow integer constants.
Parameters
----------
- resampling_algorithm : :class:`int`, an integer constant described in the Pillow library, or one from the RESAMPLING_ALGORITHMS global dictionary, under the following keys:
+ resampling_algorithm : :class:`int`, an integer constant described in the
+ Pillow library, or one from the RESAMPLING_ALGORITHMS global dictionary, under
+ the following keys:
* 'bicubic' or 'cubic'
* 'nearest' or 'none'
* 'box'
@@ -68,7 +75,10 @@ class AbstractImageMobject(Mobject):
self.resampling_algorithm = resampling_algorithm
else:
raise ValueError(
- "resampling_algorithm has to be an int, one of the values defined in RESAMPLING_ALGORITHMS or a Pillow resampling filter constant. Available algorithms: 'bicubic', 'nearest', 'box', 'bilinear', 'hamming', 'lanczos'."
+ "resampling_algorithm has to be an int, one of the values defined in "
+ "RESAMPLING_ALGORITHMS or a Pillow resampling filter constant. "
+ "Available algorithms: 'bicubic', 'nearest', 'box', 'bilinear', "
+ "'hamming', 'lanczos'."
)
def reset_points(self):
@@ -96,8 +106,11 @@ class ImageMobject(AbstractImageMobject):
Parameters
----------
scale_to_resolution : :class:`int`
- At this resolution the image is placed pixel by pixel onto the screen, so it will look the sharpest and best.
- This is a custom parameter of ImageMobject so that rendering a scene with e.g. the ``--quality low`` or ``--quality medium`` flag for faster rendering won't effect the position of the image on the screen.
+ At this resolution the image is placed pixel by pixel onto the screen, so it
+ will look the sharpest and best.
+ This is a custom parameter of ImageMobject so that rendering a scene with
+ e.g. the ``--quality low`` or ``--quality medium`` flag for faster rendering
+ won't effect the position of the image on the screen.
Example
diff --git a/manim/mobject/vector_field.py b/manim/mobject/vector_field.py
index 6955b6b44..cc77548f7 100644
--- a/manim/mobject/vector_field.py
+++ b/manim/mobject/vector_field.py
@@ -20,7 +20,7 @@ from ..animation.composition import AnimationGroup, Succession
from ..animation.creation import Create
from ..animation.indication import ShowPassingFlash
from ..animation.update import UpdateFromAlphaFunc
-from ..constants import *
+from ..constants import RIGHT, UP
from ..mobject.geometry import Vector
from ..mobject.mobject import Mobject
from ..mobject.types.vectorized_mobject import VGroup, VMobject
@@ -76,7 +76,10 @@ class VectorField(VGroup):
if color is None:
self.single_color = False
if color_scheme is None:
- color_scheme = lambda p: np.linalg.norm(p)
+
+ def color_scheme(p):
+ return np.linalg.norm(p)
+
self.color_scheme = color_scheme # TODO maybe other default for direction?
self.rgbs = np.array(list(map(color_to_rgb, colors)))
diff --git a/manim/utils/hashing.py b/manim/utils/hashing.py
index 6dce37eb4..ed9424799 100644
--- a/manim/utils/hashing.py
+++ b/manim/utils/hashing.py
@@ -14,8 +14,8 @@ import numpy as np
from .. import config, logger
-# Sometimes there are elements that are not suitable for hashing (too long or run-dependent)
-# This is used to filter them out.
+# Sometimes there are elements that are not suitable for hashing (too long or
+# run-dependent). This is used to filter them out.
KEYS_TO_FILTER_OUT = {
"original_id",
"background",
@@ -25,12 +25,16 @@ KEYS_TO_FILTER_OUT = {
class _Memoizer:
- """Implements the memoization logic to optimize the hashing procedure and prevent the circular references within iterable processed.
+ """Implements the memoization logic to optimize the hashing procedure and prevent
+ the circular references within iterable processed.
- Keeps a record of all the processed objects, and handle the logic to return a place holder instead of the original object if the object has already been processed
+ Keeps a record of all the processed objects, and handle the logic to return a place
+ holder instead of the original object if the object has already been processed
by the hashing logic (i.e, recursively checked, converted to JSON, etc..).
- This class uses two signatures functions to keep a track of processed objects : hash or id. Whenever possible, hash is used to ensure a broader object content-equality detection.
+ This class uses two signatures functions to keep a track of processed objects :
+ hash or id. Whenever possible, hash is used to ensure a broader object
+ content-equality detection.
"""
_already_processed = set()
@@ -45,7 +49,9 @@ class _Memoizer:
@classmethod
def check_already_processed_decorator(cls: "_Memoizer", is_method=False):
- """Decorator to handle the arguments that goes through the decorated function. Returns _ALREADY_PROCESSED_PLACEHOLDER if the obj has been processed, or lets the decorated function call go ahead.
+ """Decorator to handle the arguments that goes through the decorated function.
+ Returns _ALREADY_PROCESSED_PLACEHOLDER if the obj has been processed, or lets
+ the decorated function call go ahead.
Parameters
----------
@@ -54,7 +60,8 @@ class _Memoizer:
"""
def layer(func):
- # NOTE : There is probably a better way to separate both case when func is a method or a function.
+ # NOTE : There is probably a better way to separate both case when func is
+ # a method or a function.
if is_method:
return lambda self, obj: cls._handle_already_processed(
obj, default_function=lambda obj: func(self, obj)
@@ -65,7 +72,8 @@ class _Memoizer:
@classmethod
def check_already_processed(cls, obj: Any) -> Any:
- """Checks if obj has been already processed. Returns itself if it has not been, or the value of _ALREADY_PROCESSED_PLACEHOLDER if it has.
+ """Checks if obj has been already processed. Returns itself if it has not been,
+ or the value of _ALREADY_PROCESSED_PLACEHOLDER if it has.
Marks the object as processed in the second case.
Parameters
@@ -109,14 +117,15 @@ class _Memoizer:
)
and obj not in [None, cls.ALREADY_PROCESSED_PLACEHOLDER]
):
- # It makes no sense (and it'd slower) to memoize objects of these primitive types.
- # Hence, we simply return the object.
+ # It makes no sense (and it'd slower) to memoize objects of these primitive
+ # types. Hence, we simply return the object.
return obj
if isinstance(obj, collections.abc.Hashable):
try:
return cls._return(obj, hash, default_function)
except TypeError:
- # In case of an error with the hash (eg an object is marked as hashable but contains a non hashable within it)
+ # In case of an error with the hash (eg an object is marked as hashable
+ # but contains a non hashable within it)
# Fallback to use the built-in function id instead.
pass
return cls._return(obj, id, default_function)
@@ -138,11 +147,14 @@ class _Memoizer:
and len(cls._already_processed) == cls.THRESHOLD_WARNING
):
logger.warning(
- "It looks like the scene contains a lot of sub-mobjects. Caching is sometimes not suited to handle such large scenes, you might consider disabling caching with\
- --disable_caching to potentially speed up the rendering process."
+ "It looks like the scene contains a lot of sub-mobjects. Caching "
+ "is sometimes not suited to handle such large scenes, you might "
+ "consider disabling caching with --disable_caching to potentially "
+ "speed up the rendering process."
)
logger.warning(
- "You can disable this warning by setting disable_caching_warning to True in your config file."
+ "You can disable this warning by setting disable_caching_warning "
+ "to True in your config file."
)
cls._already_processed.add(obj_membership_sign)
@@ -154,10 +166,13 @@ class _CustomEncoder(json.JSONEncoder):
"""
This method is used to serialize objects to JSON format.
- If obj is a function, then it will return a dict with two keys : 'code', for the code source, and 'nonlocals' for all nonlocalsvalues. (including nonlocals functions, that will be serialized as this is recursive.)
+ If obj is a function, then it will return a dict with two keys : 'code', for
+ the code source, and 'nonlocals' for all nonlocalsvalues. (including nonlocals
+ functions, that will be serialized as this is recursive.)
if obj is a np.darray, it converts it into a list.
if obj is an object with __dict__ attribute, it returns its __dict__.
- Else, will let the JSONEncoder do the stuff, and throw an error if the type is not suitable for JSONEncoder.
+ Else, will let the JSONEncoder do the stuff, and throw an error if the type is
+ not suitable for JSONEncoder.
Parameters
----------
@@ -176,7 +191,8 @@ class _CustomEncoder(json.JSONEncoder):
cvars = inspect.getclosurevars(obj)
cvardict = {**copy.copy(cvars.globals), **copy.copy(cvars.nonlocals)}
for i in list(cvardict):
- # NOTE : All module types objects are removed, because otherwise it throws ValueError: Circular reference detected if not. TODO
+ # NOTE : All module types objects are removed, because otherwise it
+ # throws ValueError: Circular reference detected if not. TODO
if isinstance(cvardict[i], ModuleType):
del cvardict[i]
try:
diff --git a/scripts/template_twitter_post.py b/scripts/template_twitter_post.py
index 210135de9..51359587d 100644
--- a/scripts/template_twitter_post.py
+++ b/scripts/template_twitter_post.py
@@ -10,7 +10,7 @@ class TwitterScene(Scene):
self.camera.background_color = "#ece6e2"
version = Tex(f"v{version_num}").to_corner(UR).set_color(BLACK)
self.add(version)
- ## add twitter scene content here
+ # add twitter scene content here
banner = ManimBanner(dark_theme=False).scale(0.3).to_corner(DR)
self.play(FadeIn(banner))