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.
def __init__(self, value):
self._value = 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?).