On 12:20 pm, alan.is...@gmail.com wrote:
Alan G Isaac wrote:
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more
information.
class MyError(Exception):
... def __init__(self, message):
... Exception.__init__(self)
... self.message = message
...
e = MyError('msg')
__main__:4: DeprecationWarning: BaseException.message has been
deprecated as of Python 2.6
So? Why would that mean I cannot add such an attribute
to derived classes?
On 9/4/2009 6:42 PM, Terry Reedy wrote:
It does not mean that. Try printing e.message and you should see
'msg'.
I believe what it does mean is the the special meaning of
exception.message (I have forgotten what it is) is gone in Python 3.
In Py3
class MyError(Exception):
def __init__(self, message):
Exception.__init__(self)
self.message = message
e = MyError('msg')
print(e.message)
# 'msg'
No warning any more.
Exactly!
I think you are missing my point.
I understand it is just a DeprecationWarning.
But **why** should I receive a deprecation warning
when I am **not** using the deprecated practice?
Since I am **not** using the deprecated practice, the
warning is incorrect. (See the class definition above.)
And this incorrect warning affects a lot of people!
You are using the deprecated practice. Attributes are not scoped to a
particular class. There is only one "message" attribute on your
"MyError" instance. It does not belong just to "MyError". It does not
belong just to "Exception". It does not belong just to "BaseException".
It is shared by all of them. Because "BaseException" deprecates
instances of it having a "message" attribute, any instance of any
subclass of "BaseException" which uses this attribute will get the
deprecation warning. Perhaps you weren't intending to use the "message"
attribute as "BaseException" was using it, but this doesn't matter.
There is only one "message" attribute, and "BaseException" already
claimed it, and then deprecated it.
What anyone who is **not** using the deprecated practice
should expect in Python 2.6 is the Py3 behavior. That is
not what we get: we get instead an incorrect deprecation
warning.
Possibly so, but there is no way for the runtime to know that you're not
trying to use the deprecated behavior. All it can tell is that you're
using the deprecated attribute name. Perhaps you can come up with a way
for it to differentiate between these two cases and contribute a patch,
though.
Jean-Paul
--
http://mail.python.org/mailman/listinfo/python-list