Skip to content

Commit 1151ebc

Browse files
committed
Simplify __str__ method.
1 parent 8a8eb08 commit 1151ebc

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

plotly/exceptions.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,15 @@ def add_to_error_path(self, path):
109109
self.path = [path] + self.path
110110

111111
def __str__(self):
112-
message = self.message
113-
message += "\n\nPath To Error:\n["
114-
for iii, key in enumerate(self.path):
115-
message += repr(key)
116-
if iii < len(self.path) - 1:
117-
message += "]["
118-
message += "]"
119-
if len(self.notes):
120-
message += "\n\nAdditional Notes:\n{0}".format(
121-
"\n".join(self.notes))
122-
return message
112+
format_dict = {
113+
'message': self.message,
114+
'path': '[' + ']['.join(repr(k) for k in self.path) + ']',
115+
'notes': '\n'.join(self.notes)
116+
}
117+
return (
118+
'{message}\n\nPath To Error: {path}\n\nAdditional Notes:\n {notes}'
119+
.format(**format_dict)
120+
)
123121

124122

125123
class PlotlyDictKeyError(PlotlyGraphObjectError):

0 commit comments

Comments
 (0)