Python 2.6 BaseException.message deprecation, really needed?
In PyGObject we want to use a 'message' attribute in an exception defined by us. The name 'message' comes from a C API, therefore we would like to keep it for easier mapping between C and Python APIs. Why does Python have to deprecate this attribute? .../gobject/option.py:187: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 gerror.message = str(error) -- Gustavo J. A. M. Carneiro INESC Porto, Telecommunications and Multimedia Unit "The universe is always one step beyond logic." -- Frank Herbert
On 7/7/07, Gustavo Carneiro <gjcarneiro@gmail.com> wrote:
In PyGObject we want to use a 'message' attribute in an exception defined by us. The name 'message' comes from a C API, therefore we would like to keep it for easier mapping between C and Python APIs. Why does Python have to deprecate this attribute?
It's going away in Python 3.0. In retrospect the attribute was a mistake thanks to its odd semantics to be backwards compatible in a reasonable way. Plus its removal from the code base was nasty mostly thanks to C-based exceptions.
.../gobject/option.py:187: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 gerror.message = str(error)
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) -Brett
On Saturday 07 July 2007, Gustavo Carneiro wrote:
In PyGObject we want to use a 'message' attribute in an exception defined by us. The name 'message' comes from a C API, therefore we would like to keep it for easier mapping between C and Python APIs. Why does Python have to deprecate this attribute?
It can be deprecated for BaseException without it being deprecated for your exception. You'll need to define a property that overrides the property in BaseException; something like this in Python (not tested): class MyException(Exception): _message = None @apply def message(): def get(self): return self._message def set(self, value): self._message = value return property(get, set) I think your use case is entirely reasonable, and can be handled readily. -Fred -- Fred L. Drake, Jr. <fdrake at acm.org>
participants (3)
-
Brett Cannon -
Fred L. Drake, Jr. -
Gustavo Carneiro