[Python-checkins] cpython (merge 3.4 -> default): merge 3.4
benjamin.peterson
python-checkins at python.org
Mon Mar 17 22:00:38 CET 2014
http://hg.python.org/cpython/rev/007265795b1b
changeset: 89825:007265795b1b
parent: 89823:e9f136c394e2
parent: 89824:afae24cb81d9
user: Benjamin Peterson <benjamin at python.org>
date: Mon Mar 17 16:00:27 2014 -0500
summary:
merge 3.4
files:
Lib/test/test_descr.py | 8 ++++++++
Objects/typeobject.c | 17 ++++++++---------
2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4414,6 +4414,14 @@
self.assertRaises(TypeError, case, 1, 2, 3)
self.assertRaises(TypeError, case, 1, 2, foo=3)
+ def test_subclassing_does_not_duplicate_dict_descriptors(self):
+ class Base:
+ pass
+ class Sub(Base):
+ pass
+ self.assertIn("__dict__", Base.__dict__)
+ self.assertNotIn("__dict__", Sub.__dict__)
+
class DictProxyTests(unittest.TestCase):
def setUp(self):
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2472,12 +2472,6 @@
type->tp_dictoffset = slotoffset;
slotoffset += sizeof(PyObject *);
}
- else if (!type->tp_dictoffset) {
- type->tp_dictoffset = base->tp_dictoffset;
- }
- if (type->tp_dictoffset) {
- et->ht_cached_keys = _PyDict_NewKeysForClass();
- }
if (add_weak) {
assert(!base->tp_itemsize);
type->tp_weaklistoffset = slotoffset;
@@ -2527,6 +2521,10 @@
/* Put the proper slots in place */
fixup_slot_dispatchers(type);
+ if (type->tp_dictoffset) {
+ et->ht_cached_keys = _PyDict_NewKeysForClass();
+ }
+
Py_DECREF(dict);
return (PyObject *)type;
@@ -2643,9 +2641,6 @@
type->tp_doc = tp_doc;
}
}
- if (type->tp_dictoffset) {
- res->ht_cached_keys = _PyDict_NewKeysForClass();
- }
if (type->tp_dealloc == NULL) {
/* It's a heap type, so needs the heap types' dealloc.
subtype_dealloc will call the base type's tp_dealloc, if
@@ -2656,6 +2651,10 @@
if (PyType_Ready(type) < 0)
goto fail;
+ if (type->tp_dictoffset) {
+ res->ht_cached_keys = _PyDict_NewKeysForClass();
+ }
+
/* Set type.__module__ */
s = strrchr(spec->name, '.');
if (s != NULL)
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list