10000 converted assert into exception · matplotlib/matplotlib@873e91d · GitHub
[go: up one dir, main page]

Skip to content

Commit 873e91d

Browse files
committed
converted assert into exception
1 parent 6387fca commit 873e91d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/matplotlib/figure.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050

5151
docstring.interpd.update(projection_names=get_projection_names())
5252

53+
class AxesException(Exception):
54+
pass
5355

5456
class AxesStack(Stack):
5557
"""
@@ -872,7 +874,9 @@ def add_axes(self, *args, **kwargs):
872874

873875
if isinstance(args[0], Axes):
874876
a = args[0]
875-
assert(a.get_figure() is self)
877+
if a.get_figure() is not self:
878+
msg = "The Axes must have been created in the present figure"
879+
raise AxesException(msg)
876880
else:
877881
rect = args[0]
878882
projection_class, kwargs, key = process_projection_requirements(
@@ -946,7 +950,9 @@ def add_subplot(self, *args, **kwargs):
946950
if isinstance(args[0], SubplotBase):
947951

948952
a = args[0]
949-
assert(a.get_figure() is self)
953+
if a.get_figure() is not self:
954+
msg = "The Subplot must have been created in the present figure"
955+
raise AxesException(msg)
950956
# make a key for the subplot (which includes the axes object id
951957
# in the hash)
952958
key = self._make_key(*args, **kwargs)

0 commit comments

Comments
 (0)
0