Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aba9d99

Browse files
committed
Most asserts changed to ValueErrors. Two changed to warning
1 parent 4cfa781 commit aba9d99

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

lib/matplotlib/backend_bases.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,11 @@ def set_clip_path(self, path):
969969
Set the clip path and transformation. Path should be a
970970
:class:`~matplotlib.transforms.TransformedPath` instance.
971971
"""
972-
assert path is None or isinstance(path, transforms.TransformedPath)
972+
if path is not None and not isinstance(path,
973+
transforms.TransformedPath):
974+
msg = "Path should be a matplotlib.transforms.TransformedPath \
975+
instance."
976+
raise ValueError(msg)
973977
self._clippath = path
974978

975979
def set_dashes(self, dash_offset, dash_list):

lib/matplotlib/blocking_input.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
from matplotlib.cbook import is_sequence_of_strings
3131
import matplotlib.lines as mlines
3232

33+
import warnings
34+
3335

3436
class BlockingInput(object):
3537
"""
@@ -38,8 +40,8 @@ class BlockingInput(object):
3840
"""
3941
def __init__(self, fig, eventslist=()):
4042
self.fig = fig
41-
assert is_sequence_of_strings(
42-
eventslist), "Requires a sequence of event name strings"
43+
if not is_sequence_of_strings(eventslist):
44+
raise ValueError("Requires a sequence of event name strings")
4345
self.eventslist = eventslist
4446

4547
def on_event(self, event):
@@ -95,7 +97,8 @@ def __call__(self, n=1, timeout=30):
9597
Blocking call to retrieve n events
9698
"""
9799

98-
assert isinstance(n, int), "Requires an integer argument"
100+
if not isinstance(n, int):
101+
raise ValueError("Requires an integer argument")
99102
self.n = n
100103

101104
self.events = []
@@ -146,9 +149,9 @@ def post_event(self):
146149
"""
147150
This will be called to process events
148151
"""
149-
assert len(self.events) > 0, "No events yet"
150-
151-
if self.events[-1].name == 'key_press_event':
152+
if len(self.events) <= 0:
153+
warnings.warn("No events yet")
154+
elif self.events[-1].name == 'key_press_event':
152155
self.key_event()
153156
else:
154157
self.mouse_event()
@@ -359,9 +362,10 @@ def post_event(self):
359362
"""
360363
Determines if it is a key event
361364
"""
362-
assert len(self.events) > 0, "No events yet"
363-
364-
self.keyormouse = self.events[-1].name == 'key_press_event'
365+
if len(self.events) <= 0:
366+
warnings.warn("No events yet")
367+
else:
368+
self.keyormouse = self.events[-1].name == 'key_press_event'
365369

366370
def __call__(self, timeout=30):
367371
"""

0 commit comments

Comments
 (0)