incorrect DeprecationWarning?

A

Alan G Isaac

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..... def __init__(self, message):
.... Exception.__init__(self)
.... self.message = message
....__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?

Contrast:

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..... def __init__(self, message):
.... Exception.__init__(self)
.... self.msg = message
....
Beyond odd. A bug?

Alan Isaac
 
T

Terry Reedy

Alan said:
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.... def __init__(self, message):
... Exception.__init__(self)
... self.message = message
...__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?

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.
Beyond odd. A bug?

No. A warning about a 'future' change in behavior.

tjr
 
A

Alan G Isaac

Alan said:
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?



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!

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.

Alan Isaac
 
E

exarkun

Alan said:
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?



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
 
A

Alan G Isaac

You are using the deprecated practice.

Clearly not, or it would fail in Python 3,
which it does not.
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.

No, it does not belong to any of those classes.
It belongs to the instance.
Because "BaseException" deprecates
instances of it having a "message" attribute

That is what is is doing, and that is precisely the problem.
The DeprecationError is raised for the wrong thing.
I mean be serious: this is flagging the use of
a new attribute on a subclass. If you proposed building
a class that way the screams on "unPythonic" on this
list would be deafening.

I am not sure how best to deprecate dependence on the
Python 2.5 mistake, but this is not it. And I know at
least one important library that is affected.

Alan Isaac
 
T

Terry Reedy

On 12:20 pm, (e-mail address removed) wrote:

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.

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.

It is sometimes hard to warn exactly when appropriate and impossible for
the default action to satisfy everyone. The developers are, of course,
aware of this. That is why there is a mechanism to turn off particular
warnings. Checkout the extremely flexible warnings module.

tjr
 
E

exarkun

I am not sure how best to deprecate dependence on the
Python 2.5 mistake, but this is not it. And I know at
least one important library that is affected.

I'll agree that it's not great. I certainly would have preferred it not
to have been done. It is futile to complain about this kind of thing on
python-list, though. Raise the issue on python-dev. I don't think
anyone will listen to you, but who knows until you try. If you have an
alternate suggestion to make, that might help gain some traction; if
not, the issue will probably just be dismissed. Even so, I suspect
someone will say "This is irrelevant, just rename your attribute."
Python developers aren't much concerned with this kind of thing.

Cynically,
Jean-Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top