10000 Simplify how `notes` are added to errors. · ii0/plotly.py@b89be4e · GitHub
[go: up one dir, main page]

Skip to content

Commit b89be4e

Browse files
committed
Simplify how notes are added to errors.
1 parent 1151ebc commit b89be4e

File tree

3 files changed

+22
-43
lines changed

3 files changed

+22
-43
lines changed

plotly/exceptions.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,27 +81,16 @@ class PlotlyEmptyDataError(PlotlyError):
8181

8282
# Graph Objects Errors
8383
class PlotlyGraphObjectError(PlotlyError):
84-
def __init__(self, message='', path=(), notes=None, plain_message=''):
84+
def __init__(self, message='', path=(), note='', plain_message=''):
8585
self.message = message
8686
self.plain_message = plain_message
8787
if isinstance(path, (basestring, int)):
8888
self.path = [path]
8989
else:
9090
self.path = list(path)
91-
if isinstance(notes, list):
92-
self.notes = notes
93-
elif notes is None:
94-
self.notes = []
95-
else:
96-
self.notes = [notes]
91+
self.note = note
9792
super(PlotlyGraphObjectError, self).__init__(message)
9893

99-
def add_note(self, note):
100-
if isinstance(note, list):
101-
self.notes += note
102-
else:
103-
self.notes += [note]
104-
10594
def add_to_error_path(self, path):
10695
if isinstance(path, list):
10796
self.path = path + self.path
@@ -112,10 +101,10 @@ def __str__(self):
112101
format_dict = {
113102
'message': self.message,
114103
'path': '[' + ']['.join(repr(k) for k in self.path) + ']',
115-
'notes': '\n'.join(self.notes)
104+
'note': self.note
116105
}
117106
return (
118-
'{message}\n\nPath To Error: {path}\n\nAdditional Notes:\n {notes}'
107+
'{message}\n\nPath To Error: {path}\n\nAdditional Notes:\n {note}'
119108
.format(**format_dict)
120109
)
121110

plotly/graph_objs/graph_objs.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,17 @@ def __init__(self, *args, **kwargs):
140140
raise exceptions.PlotlyListEntryError(
141141
obj=self,
142142
index=0,
143-
notes="Just like a `list`, `{name}` must be instantiated with "
144-
"a *single* collection.\n"
145-
"In other words these are OK:\n"
146-
">>> {name}()\n"
147-
">>> {name}([])\n"
148-
">>> {name}([dict()])\n"
149-
">>> {name}([dict(), dict()])\n"
150-
"However, these don't make sense:\n"
151-
">>> {name}(dict())\n"
152-
">>> {name}(dict(), dict())"
153-
"".format(name=self._get_class_name())
143+
note="Just like a `list`, `{name}` must be instantiated with "
144+
"a *single* collection.\n"
145+
"In other words these are OK:\n"
146+
">>> {name}()\n"
147+
">>> {name}([])\n"
148+
">>> {name}([dict()])\n"
149+
">>> {name}([dict(), dict()])\n"
150+
"However, these don't make sense:\n"
151+
">>> {name}(dict())\n"
152+
">>> {name}(dict(), dict())"
153+
.format(name=self._get_class_name())
154154
)
155155

156156
super(PlotlyList, self).__init__()
@@ -926,9 +926,9 @@ def _value_to_graph_object(self, index, value, _raise=True):
926926

927927
if not isinstance(value, dict):
928928
if _raise:
929-
e = exceptions.PlotlyListEntryError(self, index, value)
930-
e.add_note('Entry should subclass dict.')
931-
raise e
929+
note = 'Entry should subclass dict.'
930+
raise exceptions.PlotlyListEntryError(self, index, value,
931+
note=note)
932932
else:
933933
return
934934

plotly/plotly/plotly.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,8 @@ def iplot_mpl(fig, resize=True, strip_style=False, update=None,
293293
"""
294294
fig = tools.mpl_to_plotly(fig, resize=resize, strip_style=strip_style)
295295
if update and isinstance(update, dict):
296-
try:
297-
fig.update(update)
298-
fig.validate()
299-
except exceptions.PlotlyGraphObjectError as err:
300-
err.add_note("Your updated figure could not be properly "
301-
"validated.")
302-
raise
296+
fig.update(update)
297+
fig.validate()
303298
elif update is not None:
304299
raise exceptions.PlotlyGraphObjectError(
305300
"'update' must be dictionary-like and a valid plotly Figure "
@@ -331,13 +326,8 @@ def plot_mpl(fig, resize=True, strip_style=False, update=None, **plot_options):
331326
"""
332327
fig = tools.mpl_to_plotly(fig, resize=resize, strip_style=strip_style)
333328
if update and isinstance(update, dict):
334-
try:
335-
fig.update(update)
336-
fig.validate()
337-
except exceptions.PlotlyGraphObjectError as err:
338-
err.add_note("Your updated figure could not be properly "
339-
"validated.")
340-
raise
329+
fig.update(update)
330+
fig.validate()
341331
elif update is not None:
342332
raise exceptions.PlotlyGraphObjectError(
343333
"'update' must be dictionary-like and a valid plotly Figure "

0 commit comments

Comments
 (0)
0