summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_descr.py2
-rw-r--r--Objects/funcobject.c18
2 files changed, 14 insertions, 6 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 2227779..7b9a523 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1444,6 +1444,7 @@ order (MRO) for bases """
self.fail("classmethod shouldn't accept keyword args")
cm = classmethod(f)
+ self.assertEqual(cm.__dict__, {})
cm.x = 42
self.assertEqual(cm.x, 42)
self.assertEqual(cm.__dict__, {"x" : 42})
@@ -1482,6 +1483,7 @@ order (MRO) for bases """
self.assertEqual(d.foo(1), (d, 1))
self.assertEqual(D.foo(d, 1), (d, 1))
sm = staticmethod(None)
+ self.assertEqual(sm.__dict__, {})
sm.x = 42
self.assertEqual(sm.x, 42)
self.assertEqual(sm.__dict__, {"x" : 42})
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index 089356b..6dd91b8 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -832,10 +832,13 @@ cm_get___isabstractmethod__(classmethod *cm, void *closure)
}
static PyObject *
-cm_get___dict__(classmethod *cm, void *closure)
+cm_get___dict__(PyObject *cm, void *closure)
{
- Py_INCREF(cm->cm_dict);
- return cm->cm_dict;
+ PyObject **dictptr = _PyObject_GetDictPtr(cm);
+ if (*dictptr == NULL)
+ *dictptr = PyDict_New();
+ Py_XINCREF(*dictptr);
+ return *dictptr;
}
static PyGetSetDef cm_getsetlist[] = {
@@ -1018,10 +1021,13 @@ sm_get___isabstractmethod__(staticmethod *sm, void *closure)
}
static PyObject *
-sm_get___dict__(staticmethod *sm, void *closure)
+sm_get___dict__(PyObject *sm, void *closure)
{
- Py_INCREF(sm->sm_dict);
- return sm->sm_dict;
+ PyObject **dictptr = _PyObject_GetDictPtr(sm);
+ if (*dictptr == NULL)
+ *dictptr = PyDict_New();
+ Py_XINCREF(*dictptr);
+ return *dictptr;
}
static PyGetSetDef sm_getsetlist[] = {