[Python-checkins] r77159 - in python/branches/release26-maint: Doc/c-api/structures.rst Lib/test/test_descr.py Misc/NEWS Python/structmember.c
benjamin.peterson
python-checkins at python.org
Wed Dec 30 20:41:49 CET 2009
Author: benjamin.peterson
Date: Wed Dec 30 20:41:48 2009
New Revision: 77159
Log:
Merged revisions 77157 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77157 | benjamin.peterson | 2009-12-30 13:34:10 -0600 (Wed, 30 Dec 2009) | 5 lines
check if the attribute is set before deleting it with T_OBJECT_EX (fixes #7604)
Also, add a note to the docs about the better behavior of T_OBJECT_EX as
compared to T_OBJECT.
........
Modified:
python/branches/release26-maint/ (props changed)
python/branches/release26-maint/Doc/c-api/structures.rst
python/branches/release26-maint/Lib/test/test_descr.py
python/branches/release26-maint/Misc/NEWS
python/branches/release26-maint/Python/structmember.c
Modified: python/branches/release26-maint/Doc/c-api/structures.rst
==============================================================================
--- python/branches/release26-maint/Doc/c-api/structures.rst (original)
+++ python/branches/release26-maint/Doc/c-api/structures.rst Wed Dec 30 20:41:48 2009
@@ -281,7 +281,10 @@
:cmacro:`T_OBJECT` and :cmacro:`T_OBJECT_EX` differ in that
:cmacro:`T_OBJECT` returns ``None`` if the member is *NULL* and
- :cmacro:`T_OBJECT_EX` raises an :exc:`AttributeError`.
+ :cmacro:`T_OBJECT_EX` raises an :exc:`AttributeError`. Try to use
+ :cmacro:`T_OBJECT_EX` over :cmacro:`T_OBJECT` because :cmacro:`T_OBJECT_EX`
+ handles use of the :stmt:`del` statement on that attribute more correctly
+ than :cmacro:`T_OBJECT`.
:attr:`flags` can be 0 for write and read access or :cmacro:`READONLY` for
read-only access. Using :cmacro:`T_STRING` for :attr:`type` implies
Modified: python/branches/release26-maint/Lib/test/test_descr.py
==============================================================================
--- python/branches/release26-maint/Lib/test/test_descr.py (original)
+++ python/branches/release26-maint/Lib/test/test_descr.py Wed Dec 30 20:41:48 2009
@@ -1142,6 +1142,11 @@
del h
self.assertEqual(s.getvalue(), '')
+ class X(object):
+ __slots__ = "a"
+ with self.assertRaises(AttributeError):
+ del X().a
+
def test_slots_special(self):
# Testing __dict__ and __weakref__ in __slots__...
class D(object):
Modified: python/branches/release26-maint/Misc/NEWS
==============================================================================
--- python/branches/release26-maint/Misc/NEWS (original)
+++ python/branches/release26-maint/Misc/NEWS Wed Dec 30 20:41:48 2009
@@ -12,6 +12,9 @@
Core and Builtins
-----------------
+- Issue #7604: Deleting an unset slotted attribute did not raise an
+ AttributeError.
+
- Issue #7413: Passing '\0' as the separator to datetime.datetime.isoformat()
used to drop the time part of the result.
Modified: python/branches/release26-maint/Python/structmember.c
==============================================================================
--- python/branches/release26-maint/Python/structmember.c (original)
+++ python/branches/release26-maint/Python/structmember.c Wed Dec 30 20:41:48 2009
@@ -170,6 +170,8 @@
{
PyObject *oldv;
+ addr += l->offset;
+
if ((l->flags & READONLY) || l->type == T_STRING)
{
PyErr_SetString(PyExc_TypeError, "readonly attribute");
@@ -179,12 +181,20 @@
PyErr_SetString(PyExc_RuntimeError, "restricted attribute");
return -1;
}
- if (v == NULL && l->type != T_OBJECT_EX && l->type != T_OBJECT) {
- PyErr_SetString(PyExc_TypeError,
- "can't delete numeric/char attribute");
- return -1;
+ if (v == NULL) {
+ if (l->type == T_OBJECT_EX) {
+ /* Check if the attribute is set. */
+ if (*(PyObject **)addr == NULL) {
+ PyErr_SetString(PyExc_AttributeError, l->name);
+ return -1;
+ }
+ }
+ else if (l->type != T_OBJECT) {
+ PyErr_SetString(PyExc_TypeError,
+ "can't delete numeric/char attribute");
+ return -1;
+ }
}
- addr += l->offset;
switch (l->type) {
case T_BOOL:{
if (!PyBool_Check(v)) {
More information about the Python-checkins
mailing list