with self.assertRaisesRegex(NotImplementedError, "BAR"):
B().foo
+ def test_staticmethod_new(self):
+ class MyStaticMethod(staticmethod):
+ def __init__(self, func):
+ pass
+ def func(): pass
+ sm = MyStaticMethod(func)
+ self.assertEqual(repr(sm), '<staticmethod(None)>')
+ self.assertIsNone(sm.__func__)
+ self.assertIsNone(sm.__wrapped__)
+
+ def test_classmethod_new(self):
+ class MyClassMethod(classmethod):
+ def __init__(self, func):
+ pass
+ def func(): pass
+ cm = MyClassMethod(func)
+ self.assertEqual(repr(cm), '<classmethod(None)>')
+ self.assertIsNone(cm.__func__)
+ self.assertIsNone(cm.__wrapped__)
+
class DictProxyTests(unittest.TestCase):
def setUp(self):
return PyMethod_New(cm->cm_callable, type);
}
+static PyObject *
+cm_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ classmethod *cm = (classmethod *)PyType_GenericAlloc(type, 0);
+ if (cm == NULL) {
+ return NULL;
+ }
+ cm->cm_callable = Py_None;
+ cm->cm_dict = NULL;
+ return (PyObject *)cm;
+}
+
static int
cm_init(PyObject *self, PyObject *args, PyObject *kwds)
{
offsetof(classmethod, cm_dict), /* tp_dictoffset */
cm_init, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
- PyType_GenericNew, /* tp_new */
+ cm_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
};
return Py_NewRef(sm->sm_callable);
}
+static PyObject *
+sm_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ staticmethod *sm = (staticmethod *)PyType_GenericAlloc(type, 0);
+ if (sm == NULL) {
+ return NULL;
+ }
+ sm->sm_callable = Py_None;
+ sm->sm_dict = NULL;
+ return (PyObject *)sm;
+}
+
static int
sm_init(PyObject *self, PyObject *args, PyObject *kwds)
{
offsetof(staticmethod, sm_dict), /* tp_dictoffset */
sm_init, /* tp_init */
PyType_GenericAlloc, /* tp_alloc */
- PyType_GenericNew, /* tp_new */
+ sm_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
};