[Python-Dev] Inconsistent exception for read-only properties?
Barry Warsaw
barry at python.org
Fri Apr 15 05:46:04 CEST 2005
I've noticed an apparent inconsistency in the exception thrown for
read-only properties for C extension types vs. Python new-style
classes. I'm wondering if this is intentional, a bug, a bug worth
fixing, or whether I'm just missing something.
class other(object):
def __init__(self, value):
self._value = value
def _get_value(self):
return self._value
value = property(_get_value)
With this class, if you attempt "other(1).value = 7" you will get an
AttributeError. However, if you define something similar in C using a
tp_getset, where the structure has NULL for the setter, you will get a
TypeError (code available upon request).
At best, this is inconsistent. What's the "right" exception to raise?
I think the documentation I've seen (e.g. Raymond's How To for
Descriptors) describes AttributeError as the thing to raise when trying
to set read-only properties.
Thoughts? Should this be fixed (in 2.4?).
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 307 bytes
Desc: This is a digitally signed message part
Url : http://mail.python.org/pipermail/python-dev/attachments/20050414/433916e8/attachment-0001.pgp
More information about the Python-Dev
mailing list