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

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to