Skip to content

Commit 820bfc7

Browse files
Fixed errors reported by flake8 (ManimCommunity#3231)
* rewrite some list comprehensions as generator expressions * fixed flake's docstring warnings * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * one more generator expression in tests/ --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 0902eef commit 820bfc7

File tree

17 files changed

+125
-121
lines changed

17 files changed

+125
-121
lines changed

manim/_config/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ def quality(self):
11721172
keys = ["pixel_width", "pixel_height", "frame_rate"]
11731173
q = {k: self[k] for k in keys}
11741174
for qual in constants.QUALITIES:
1175-
if all([q[k] == constants.QUALITIES[qual][k] for k in keys]):
1175+
if all(q[k] == constants.QUALITIES[qual][k] for k in keys):
11761176
return qual
11771177
return None
11781178

manim/camera/camera.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,10 @@ def display_point_cloud(
886886
thickness: float,
887887
pixel_array: np.ndarray,
888888
):
889-
"""Displays a PMobject by modifying the Pixel array suitably..
889+
"""Displays a PMobject by modifying the pixel array suitably.
890+
890891
TODO: Write a description for the rgbas argument.
892+
891893
Parameters
892894
----------
893895
pmobject
@@ -1122,17 +1124,19 @@ def on_screen_pixels(self, pixel_coords: np.ndarray):
11221124
],
11231125
)
11241126

1125-
def adjusted_thickness(self, thickness: float):
1126-
"""
1127+
def adjusted_thickness(self, thickness: float) -> float:
1128+
"""Computes the adjusted stroke width for a zoomed camera.
11271129
11281130
Parameters
11291131
----------
11301132
thickness
1133+
The stroke width of a mobject.
11311134
11321135
Returns
11331136
-------
11341137
float
1135-
1138+
The adjusted stroke width that reflects zooming in with
1139+
the camera.
11361140
"""
11371141
# TODO: This seems...unsystematic
11381142
big_sum = op.add(config["pixel_height"], config["pixel_width"])
@@ -1141,7 +1145,8 @@ def adjusted_thickness(self, thickness: float):
11411145
return 1 + (thickness - 1) * factor
11421146

11431147
def get_thickening_nudges(self, thickness: float):
1144-
"""
1148+
"""Determine a list of vectors used to nudge
1149+
two-dimensional pixel coordinates.
11451150
11461151
Parameters
11471152
----------
@@ -1215,13 +1220,16 @@ def get_coords_of_all_pixels(self):
12151220
# NOTE: The methods of the following class have not been mentioned outside of their definitions.
12161221
# Their DocStrings are not as detailed as preferred.
12171222
class BackgroundColoredVMobjectDisplayer:
1223+
"""Auxiliary class that handles displaying vectorized mobjects with
1224+
a set background image.
1225+
1226+
Parameters
1227+
----------
1228+
camera
1229+
Camera object to use.
1230+
"""
1231+
12181232
def __init__(self, camera: Camera):
1219-
"""
1220-
Parameters
1221-
----------
1222-
camera
1223-
Camera object to use.
1224-
"""
12251233
self.camera = camera
12261234
self.file_name_to_pixel_array_map = {}
12271235
self.pixel_array = np.array(camera.pixel_array)

manim/mobject/geometry/arc.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,9 @@ def __init__(self, width: float = 2, height: float = 1, **kwargs):
777777

778778

779779
class AnnularSector(Arc):
780-
"""
780+
"""A sector of an annulus.
781+
782+
781783
Parameters
782784
----------
783785
inner_radius
@@ -862,7 +864,8 @@ def generate_points(self):
862864

863865

864866
class Sector(AnnularSector):
865-
"""
867+
"""A sector of a circle.
868+
866869
Examples
867870
--------
868871
.. manim:: ExampleSector
@@ -935,7 +938,8 @@ def generate_points(self):
935938

936939

937940
class CubicBezier(VMobject, metaclass=ConvertToOpenGL):
938-
"""
941+
"""A cubic Bézier curve.
942+
939943
Example
940944
-------
941945
.. manim:: BezierSplineExample

manim/mobject/graphing/probability.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434

3535

3636
class SampleSpace(Rectangle):
37-
"""
37+
"""A mobject representing a twodimensional rectangular
38+
sampling space.
3839
3940
Examples
4041
--------

manim/mobject/graphing/scale.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414

1515

1616
class _ScaleBase:
17-
"""Scale baseclass for graphing/functions."""
17+
"""Scale baseclass for graphing/functions.
18+
19+
Parameters
20+
----------
21+
custom_labels
22+
Whether to create custom labels when plotted on a :class:`~.NumberLine`.
23+
"""
1824

1925
def __init__(self, custom_labels: bool = False):
20-
"""
21-
Parameters
22-
----------
23-
custom_labels
24-
Whether to create custom labels when plotted on a :class:`~.NumberLine`.
25-
"""
2626
self.custom_labels = custom_labels
2727

2828
def function(self, value: float) -> float:

manim/mobject/matrix.py

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,39 @@ def matrix_to_mobject(matrix):
7474
class Matrix(VMobject, metaclass=ConvertToOpenGL):
7575
"""A mobject that displays a matrix on the screen.
7676
77+
Parameters
78+
----------
79+
matrix
80+
A numpy 2d array or list of lists.
81+
v_buff
82+
Vertical distance between elements, by default 0.8.
83+
h_buff
84+
Horizontal distance between elements, by default 1.3.
85+
bracket_h_buff
86+
Distance of the brackets from the matrix, by default ``MED_SMALL_BUFF``.
87+
bracket_v_buff
88+
Height of the brackets, by default ``MED_SMALL_BUFF``.
89+
add_background_rectangles_to_entries
90+
``True`` if should add backgraound rectangles to entries, by default ``False``.
91+
include_background_rectangle
92+
``True`` if should include background rectangle, by default ``False``.
93+
element_to_mobject
94+
The mobject class used to construct the elements, by default :class:`~.MathTex`.
95+
element_to_mobject_config
96+
Additional arguments to be passed to the constructor in ``element_to_mobject``,
97+
by default ``{}``.
98+
element_alignment_corner
99+
The corner to which elements are aligned, by default ``DR``.
100+
left_bracket
101+
The left bracket type, by default ``"["``.
102+
right_bracket
103+
The right bracket type, by default ``"]"``.
104+
stretch_brackets
105+
``True`` if should stretch the brackets to fit the height of matrix contents, by default ``True``.
106+
bracket_config
107+
Additional arguments to be passed to :class:`~.MathTex` when constructing
108+
the brackets.
109+
77110
Examples
78111
--------
79112
The first example shows a variety of uses of this module while the second example
@@ -146,43 +179,6 @@ def __init__(
146179
bracket_config: dict = {},
147180
**kwargs,
148181
):
149-
"""
150-
151-
Parameters
152-
----------
153-
matrix
154-
A numpy 2d array or list of lists.
155-
v_buff
156-
Vertical distance between elements, by default 0.8.
157-
h_buff
158-
Horizontal distance between elements, by default 1.3.
159-
bracket_h_buff
160-
Distance of the brackets from the matrix, by default ``MED_SMALL_BUFF``.
161-
bracket_v_buff
162-
Height of the brackets, by default ``MED_SMALL_BUFF``.
163-
add_background_rectangles_to_entries
164-
``True`` if should add backgraound rectangles to entries, by default ``False``.
165-
include_background_rectangle
166-
``True`` if should include background rectangle, by default ``False``.
167-
element_to_mobject
168-
The mobject class used to construct the elements, by default :class:`~.MathTex`.
169-
element_to_mobject_config
170-
Additional arguments to be passed to the constructor in ``element_to_mobject``,
171-
by default ``{}``.
172-
element_alignment_corner
173-
The corner to which elements are aligned, by default ``DR``.
174-
left_bracket
175-
The left bracket type, by default ``"["``.
176-
right_bracket
177-
The right bracket type, by default ``"]"``.
178-
stretch_brackets
179-
``True`` if should stretch the brackets to fit the height of matrix contents, by default ``True``.
180-
bracket_config
181-
Additional arguments to be passed to :class:`~.MathTex` when constructing
182-
the brackets.
183-
184-
"""
185-
186182
self.v_buff = v_buff
187183
self.h_buff = h_buff
188184
self.bracket_h_buff = bracket_h_buff

manim/mobject/opengl/opengl_mobject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2725,7 +2725,7 @@ def throw_error_if_no_points(self):
27252725

27262726
class OpenGLGroup(OpenGLMobject):
27272727
def __init__(self, *mobjects, **kwargs):
2728-
if not all([isinstance(m, OpenGLMobject) for m in mobjects]):
2728+
if not all(isinstance(m, OpenGLMobject) for m in mobjects):
27292729
raise Exception("All submobjects must be of type OpenGLMobject")
27302730
super().__init__(**kwargs)
27312731
self.add(*mobjects)

manim/mobject/opengl/opengl_point_cloud_mobject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def get_mobject_type_class():
162162

163163
class OpenGLPGroup(OpenGLPMobject):
164164
def __init__(self, *pmobs, **kwargs):
165-
if not all([isinstance(m, OpenGLPMobject) for m in pmobs]):
165+
if not all(isinstance(m, OpenGLPMobject) for m in pmobs):
166166
raise Exception("All submobjects must be of type OpenglPMObject")
167167
super().__init__(**kwargs)
168168
self.add(*pmobs)

manim/mobject/opengl/opengl_vectorized_mobject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1676,7 +1676,7 @@ def construct(self):
16761676
"""
16771677

16781678
def __init__(self, *vmobjects, **kwargs):
1679-
if not all([isinstance(m, OpenGLVMobject) for m in vmobjects]):
1679+
if not all(isinstance(m, OpenGLVMobject) for m in vmobjects):
16801680
raise Exception("All submobjects must be of type OpenGLVMobject")
16811681
super().__init__(**kwargs)
16821682
self.add(*vmobjects)

manim/mobject/table.py

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,43 @@ def construct(self):
8989
class Table(VGroup):
9090
"""A mobject that displays a table on the screen.
9191
92+
Parameters
93+
----------
94+
table
95+
A 2D array or list of lists. Content of the table has to be a valid input
96+
for the callable set in ``element_to_mobject``.
97+
row_labels
98+
List of :class:`~.VMobject` representing the labels of each row.
99+
col_labels
100+
List of :class:`~.VMobject` representing the labels of each column.
101+
top_left_entry
102+
The top-left entry of the table, can only be specified if row and
103+
column labels are given.
104+
v_buff
105+
Vertical buffer passed to :meth:`~.Mobject.arrange_in_grid`, by default 0.8.
106+
h_buff
107+
Horizontal buffer passed to :meth:`~.Mobject.arrange_in_grid`, by default 1.3.
108+
include_outer_lines
109+
``True`` if the table should include outer lines, by default False.
110+
add_background_rectangles_to_entries
111+
``True`` if background rectangles should be added to entries, by default ``False``.
112+
entries_background_color
113+
Background color of entries if ``add_background_rectangles_to_entries`` is ``True``.
114+
include_background_rectangle
115+
``True`` if the table should have a background rectangle, by default ``False``.
116+
background_rectangle_color
117+
Background color of table if ``include_background_rectangle`` is ``True``.
118+
element_to_mobject
119+
The :class:`~.Mobject` class applied to the table entries. by default :class:`~.Paragraph`. For common choices, see :mod:`~.text_mobject`/:mod:`~.tex_mobject`.
120+
element_to_mobject_config
121+
Custom configuration passed to :attr:`element_to_mobject`, by default {}.
122+
arrange_in_grid_config
123+
Dict passed to :meth:`~.Mobject.arrange_in_grid`, customizes the arrangement of the table.
124+
line_config
125+
Dict passed to :class:`~.Line`, customizes the lines of the table.
126+
kwargs
127+
Additional arguments to be passed to :class:`~.VGroup`.
128+
92129
Examples
93130
--------
94131
@@ -172,45 +209,6 @@ def __init__(
172209
line_config: dict = {},
173210
**kwargs,
174211
):
175-
"""
176-
Parameters
177-
----------
178-
table
179-
A 2D array or list of lists. Content of the table has to be a valid input
180-
for the callable set in ``element_to_mobject``.
181-
row_labels
182-
List of :class:`~.VMobject` representing the labels of each row.
183-
col_labels
184-
List of :class:`~.VMobject` representing the labels of each column.
185-
top_left_entry
186-
The top-left entry of the table, can only be specified if row and
187-
column labels are given.
188-
v_buff
189-
Vertical buffer passed to :meth:`~.Mobject.arrange_in_grid`, by default 0.8.
190-
h_buff
191-
Horizontal buffer passed to :meth:`~.Mobject.arrange_in_grid`, by default 1.3.
192-
include_outer_lines
193-
``True`` if the table should include outer lines, by default False.
194-
add_background_rectangles_to_entries
195-
``True`` if background rectangles should be added to entries, by default ``False``.
196-
entries_background_color
197-
Background color of entries if ``add_background_rectangles_to_entries`` is ``True``.
198-
include_background_rectangle
199-
``True`` if the table should have a background rectangle, by default ``False``.
200-
background_rectangle_color
201-
Background color of table if ``include_background_rectangle`` is ``True``.
202-
element_to_mobject
203-
The :class:`~.Mobject` class applied to the table entries. by default :class:`~.Paragraph`. For common choices, see :mod:`~.text_mobject`/:mod:`~.tex_mobject`.
204-
element_to_mobject_config
205-
Custom configuration passed to :attr:`element_to_mobject`, by default {}.
206-
arrange_in_grid_config
207-
Dict passed to :meth:`~.Mobject.arrange_in_grid`, customizes the arrangement of the table.
208-
line_config
209-
Dict passed to :class:`~.Line`, customizes the lines of the table.
210-
kwargs
211-
Additional arguments to be passed to :class:`~.VGroup`.
212-
"""
213-
214212
self.row_labels = row_labels
215213
self.col_labels = col_labels
216214
self.top_left_entry = top_left_entry

0 commit comments

Comments
 (0)