From: W. Trevor King Date: Tue, 1 Jan 2013 02:14:12 +0000 (-0500) Subject: swc-installation-test-2.py: Avoid BaseException.message warning X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=986c677bcaa837c5cebaf9d9aa63ea2ff38bf7c2;p=swc-workshop.git swc-installation-test-2.py: Avoid BaseException.message warning Dodge the logic which (at least in Python 2.6.1) raises: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 We're setting the .message attribute explicitly, so the deprecation warning does not apply to us. The fix was suggested by Brett Cannon: On Sun Jul 8 02:42:18 CEST 2007, Brett Cannon wrote [1]: > You can get around this easily enough with a subclass that uses a > property for message:: > > class gerror(Exception): > def _get_message(self, message): return self._message > def _set_message(self, message): self._message = message > message = property(_get_message, _set_message) [1]: http://mail.python.org/pipermail/python-dev/2007-July/073777.html --- diff --git a/swc-installation-test-2.py b/swc-installation-test-2.py index 0a59778..1f998ba 100755 --- a/swc-installation-test-2.py +++ b/swc-installation-test-2.py @@ -86,7 +86,14 @@ CHECKER = {} class DependencyError (Exception): + def _get_message(self): + return self._message + def _set_message(self, message): + self._message = message + message = property(_get_message, _set_message) + def __init__(self, checker, message): + super(DependencyError, self).__init__(message) self.checker = checker self.message = message