]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
As per discussion on python-dev, descriptors defined in C with a NULL setter
authorBarry Warsaw <barry@python.org>
Tue, 19 Apr 2005 23:43:40 +0000 (23:43 +0000)
committerBarry Warsaw <barry@python.org>
Tue, 19 Apr 2005 23:43:40 +0000 (23:43 +0000)
now raise AttributeError instead of TypeError, for consistency with their
pure-Python equivalent.

Misc/NEWS
Objects/descrobject.c

index ec30734f30d8129f93526fdece387e524bb983f2..01a1c733331dddbad70ecc8aeac342ee6b807cac 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,11 @@ What's New in Python 2.5 alpha 1?
 Core and builtins
 -----------------
 
+- Descriptors defined in C with a PyGetSetDef structure, where the setter is
+  NULL, now raise an AttributeError when attempting to set or delete the
+  attribute.  Previously a TypeError was raised, but this was inconsistent
+  with the equivalent pure-Python implementation.
+
 - It is now safe to call PyGILState_Release() before
   PyEval_InitThreads() (note that if there is reason to believe there
   are multiple threads around you still must call PyEval_InitThreads()
index 7d523cf2014c87742afa0af6c26ea4b4150f3166..4aa131378d2b6db93104c1ee9e84598ac9c7cb62 100644 (file)
@@ -144,7 +144,7 @@ getset_get(PyGetSetDescrObject *descr, PyObject *obj, PyObject *type)
                return res;
        if (descr->d_getset->get != NULL)
                return descr->d_getset->get(obj, descr->d_getset->closure);
-       PyErr_Format(PyExc_TypeError,
+       PyErr_Format(PyExc_AttributeError,
                     "attribute '%.300s' of '%.100s' objects is not readable",
                     descr_name((PyDescrObject *)descr),
                     descr->d_type->tp_name);
@@ -199,7 +199,7 @@ getset_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value)
        if (descr->d_getset->set != NULL)
                return descr->d_getset->set(obj, value,
                                            descr->d_getset->closure);
-       PyErr_Format(PyExc_TypeError,
+       PyErr_Format(PyExc_AttributeError,
                     "attribute '%.300s' of '%.100s' objects is not writable",
                     descr_name((PyDescrObject *)descr),
                     descr->d_type->tp_name);