Skip to content

Commit 9765c9c

Browse files
committed
Changing Exception() uses to more specific subclasses
Changed many of the Exception("message") calls to other subclasses, like ValueError, TypeError, NotImplementedError, according to python documentation at https://docs.python.org/3/library/exceptions.html I only changed exceptions for their subclasses so try/except clauses will not broke. I did with most care, and I did not change Exceptions of which use i was not sure.
1 parent dde2228 commit 9765c9c

19 files changed

+34
-34
lines changed

manim/animation/creation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def interpolate_submobject(self, submob, start_submob, alpha):
3737
submob.pointwise_become_partial(start_submob, *self.get_bounds(alpha))
3838

3939
def get_bounds(self, alpha):
40-
raise Exception("Not Implemented")
40+
raise NotImplementedError()
4141

4242

4343
class ShowCreation(ShowPartial):
@@ -69,7 +69,7 @@ def __init__(self, vmobject, **kwargs):
6969

7070
def check_validity_of_input(self, vmobject):
7171
if not isinstance(vmobject, VMobject):
72-
raise Exception("DrawBorderThenFill only works for VMobjects")
72+
raise TypeError("DrawBorderThenFill only works for VMobjects")
7373

7474
def begin(self):
7575
self.outline = self.get_outline()

manim/animation/numbers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, decimal_mob, number_update_func, **kwargs):
2323

2424
def check_validity_of_input(self, decimal_mob):
2525
if not isinstance(decimal_mob, DecimalNumber):
26-
raise Exception("ChangingDecimal can only take " "in a DecimalNumber")
26+
raise TypeError("ChangingDecimal can only take " "in a DecimalNumber")
2727

2828
def yell_about_depricated_configuration(self, **kwargs):
2929
# Obviously this would optimally be removed at

manim/animation/specialized.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self, car, target_point, **kwargs):
2929

3030
def check_if_input_is_car(self, car):
3131
if not isinstance(car, Car):
32-
raise Exception("MoveCar must take in Car object")
32+
raise TypeError("MoveCar must take in Car object")
3333

3434
def begin(self):
3535
super().begin()

manim/animation/transform.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def create_target(self):
8484
def check_target_mobject_validity(self):
8585
if self.target_mobject is None:
8686
message = "{}.create_target not properly implemented"
87-
raise Exception(message.format(self.__class__.__name__))
87+
raise NotImplementedError(message.format(self.__class__.__name__))
8888

8989
def clean_up_from_scene(self, scene):
9090
super().clean_up_from_scene(scene)
@@ -157,7 +157,7 @@ def __init__(self, mobject, **kwargs):
157157

158158
def check_validity_of_input(self, mobject):
159159
if not hasattr(mobject, "target"):
160-
raise Exception(
160+
raise ValueError(
161161
"MoveToTarget called on mobject" "without attribute 'target'"
162162
)
163163

@@ -179,7 +179,7 @@ def __init__(self, method, *args, **kwargs):
179179

180180
def check_validity_of_input(self, method):
181181
if not inspect.ismethod(method):
182-
raise Exception(
182+
raise ValueError(
183183
"Whoops, looks like you accidentally invoked "
184184
"the method you want to animate"
185185
)
@@ -244,7 +244,7 @@ def __init__(self, function, mobject, **kwargs):
244244
def create_target(self):
245245
target = self.function(self.mobject.copy())
246246
if not isinstance(target, Mobject):
247-
raise Exception(
247+
raise TypeError(
248248
"Functions passed to ApplyFunction must return object of type Mobject"
249249
)
250250
return target
@@ -266,7 +266,7 @@ def initialize_matrix(self, matrix):
266266
new_matrix[:2, :2] = matrix
267267
matrix = new_matrix
268268
elif matrix.shape != (3, 3):
269-
raise Exception("Matrix has bad dimensions")
269+
raise ValueError("Matrix has bad dimensions")
270270
return matrix
271271

272272

manim/mobject/coordinate_systems.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ def __init__(self, dim=2):
4141
self.y_max = config["frame_y_radius"]
4242

4343
def coords_to_point(self, *coords):
44-
raise Exception("Not implemented")
44+
raise NotImplementedError()
4545

4646
def point_to_coords(self, point):
47-
raise Exception("Not implemented")
47+
raise NotImplementedError()
4848

4949
def c2p(self, *coords):
5050
"""Abbreviation for coords_to_point"""
@@ -55,7 +55,7 @@ def p2c(self, point):
5555
return self.point_to_coords(point)
5656

5757
def get_axes(self):
58-
raise Exception("Not implemented")
58+
raise NotImplementedError()
5959

6060
def get_axis(self, index):
6161
return self.get_axes()[index]

manim/mobject/mobject.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ def set_colors_by_radial_gradient(
670670

671671
def set_submobject_colors_by_gradient(self, *colors):
672672
if len(colors) == 0:
673-
raise Exception("Need at least one color")
673+
raise ValueError("Need at least one color")
674674
elif len(colors) == 1:
675675
return self.set_color(*colors)
676676

@@ -1182,6 +1182,6 @@ class Group(Mobject):
11821182

11831183
def __init__(self, *mobjects, **kwargs):
11841184
if not all([isinstance(m, Mobject) for m in mobjects]):
1185-
raise Exception("All submobjects must be of type Mobject")
1185+
raise TypeError("All submobjects must be of type Mobject")
11861186
Mobject.__init__(self, **kwargs)
11871187
self.add(*mobjects)

manim/mobject/svg/drawings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ def __init__(self, suit_name, **kwargs):
10011001
"clubs": self.black,
10021002
}
10031003
if suit_name not in suits_to_colors:
1004-
raise Exception("Invalid suit name")
1004+
raise ValueError("Invalid suit name")
10051005
SVGMobject.__init__(self, file_name=suit_name, **kwargs)
10061006

10071007
color = suits_to_colors[suit_name]

manim/mobject/svg/svg_mobject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def handle_command(self, command, coord_string):
396396
# TODO, this is a suboptimal approximation
397397
new_points = np.append([new_points[0]], new_points, axis=0)
398398
elif command == "A": # elliptical Arc
399-
raise Exception("Not implemented")
399+
raise NotImplementedError("Not yet implemented")
400400
elif command == "Z": # closepath
401401
return
402402

manim/mobject/svg/tex_mobject.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def set_color_by_tex_to_color_map(self, texs_to_color_map, **kwargs):
249249
def index_of_part(self, part):
250250
split_self = self.split()
251251
if part not in split_self:
252-
raise Exception("Trying to get index of part not in MathTex")
252+
raise ValueError("Trying to get index of part not in MathTex")
253253
return split_self.index(part)
254254

255255
def index_of_part_by_tex(self, tex, **kwargs):
@@ -292,7 +292,7 @@ def fade_all_but(self, index_or_string, opacity=0.5):
292292
elif isinstance(arg, int):
293293
part = self.submobjects[arg]
294294
else:
295-
raise Exception("Expected int or string, got {0}".format(arg))
295+
raise TypeError("Expected int or string, got {0}".format(arg))
296296
for other_part in self.submobjects:
297297
if other_part is part:
298298
other_part.set_fill(opacity=1)

manim/mobject/types/image_mobject.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class AbstractImageMobject(Mobject):
2727
}
2828

2929
def get_pixel_array(self):
30-
raise Exception("Not implemented")
30+
raise NotImplementedError()
3131

3232
def set_color(self):
3333
# Likely to be implemented in subclasses, but no obgligation

0 commit comments

Comments
 (0)