Skip to content

Commit

Permalink
RobotError: Don't call __init__() supermethod
Browse files Browse the repository at this point in the history
First of all, the change introduced in
330ce55 is not PEP8-compliant (too long
line) and also I think it's a bit odd to call the __init__() method of
Exception *without* giving it a status attribute and then setting it in
our own __init__().

Setting self.message and self.status directly is also documented in the
official Python documentation, so we don't rely on internals here as
well, see:

https://docs.python.org/3/tutorial/errors.html#user-defined-exceptions

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
  • Loading branch information
aszlig committed Jun 24, 2017
1 parent c597879 commit 788b3fd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions hetzner/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
class RobotError(Exception):
def __init__(self, message, status=None):
formattedMessage = message if status is None else "{0} ({1})".format(message, status)
super(Exception, self).__init__(formattedMessage)
if status is None:
self.message = message
else:
self.message = "{0} ({1})".format(message, status)
self.status = status


Expand Down

0 comments on commit 788b3fd

Please sign in to comment.