diff -r d0e2437136f5 Objects/typeobject.c
--- a/Objects/typeobject.c Sun Jan 19 03:01:23 2014 -0800
+++ b/Objects/typeobject.c Mon Jan 20 16:42:40 2014 +0800
@@ -6,6 +6,16 @@
#include
+/*[clinic input]
+class type
+[clinic start generated code]*/
+/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
+
+/*[python input]
+class PyTypeObject_converter(self_converter):
+ type = "PyTypeObject *"
+[python start generated code]*/
+/*[python end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/
/* Support type attribute cache */
@@ -3899,28 +3909,93 @@
return res;
}
+/*[clinic input]
+
+type.__reduce__
+
+ proto: int = 0
+ /
+
+Helper for pickle
+[clinic start generated code]*/
+
+PyDoc_STRVAR(type___reduce____doc__,
+"__reduce__(proto=0)\n"
+"Helper for pickle");
+
+#define TYPE___REDUCE___METHODDEF \
+ {"__reduce__", (PyCFunction)type___reduce__, METH_VARARGS, type___reduce____doc__},
+
static PyObject *
-object_reduce(PyObject *self, PyObject *args)
-{
+type___reduce___impl(PyObject *self, int proto);
+
+static PyObject *
+type___reduce__(PyObject *self, PyObject *args)
+{
+ PyObject *return_value = NULL;
int proto = 0;
- if (!PyArg_ParseTuple(args, "|i:__reduce__", &proto))
- return NULL;
-
+ if (!PyArg_ParseTuple(args,
+ "|i:__reduce__",
+ &proto))
+ goto exit;
+ return_value = type___reduce___impl(self, proto);
+
+exit:
+ return return_value;
+}
+
+static PyObject *
+type___reduce___impl(PyObject *self, int proto)
+/*[clinic end generated code: checksum=1e9562bf755631b0c7566482c4567e424e8dcf4e]*/
+{
return _common_reduce(self, proto);
}
+/*[clinic input]
+
+type.__reduce_ex__
+
+ proto: int = 0
+ /
+
+Helper for pickle
+[clinic start generated code]*/
+
+PyDoc_STRVAR(type___reduce_ex____doc__,
+"__reduce_ex__(proto=0)\n"
+"Helper for pickle");
+
+#define TYPE___REDUCE_EX___METHODDEF \
+ {"__reduce_ex__", (PyCFunction)type___reduce_ex__, METH_VARARGS, type___reduce_ex____doc__},
+
static PyObject *
-object_reduce_ex(PyObject *self, PyObject *args)
+type___reduce_ex___impl(PyObject *self, int proto);
+
+static PyObject *
+type___reduce_ex__(PyObject *self, PyObject *args)
+{
+ PyObject *return_value = NULL;
+ int proto = 0;
+
+ if (!PyArg_ParseTuple(args,
+ "|i:__reduce_ex__",
+ &proto))
+ goto exit;
+ return_value = type___reduce_ex___impl(self, proto);
+
+exit:
+ return return_value;
+}
+
+static PyObject *
+type___reduce_ex___impl(PyObject *self, int proto)
+/*[clinic end generated code: checksum=80173b4951026151bcc911e112b3d3cbc2f0abf8]*/
{
static PyObject *objreduce;
PyObject *reduce, *res;
- int proto = 0;
_Py_IDENTIFIER(__reduce__);
- if (!PyArg_ParseTuple(args, "|i:__reduce_ex__", &proto))
- return NULL;
-
if (objreduce == NULL) {
objreduce = _PyDict_GetItemId(PyBaseObject_Type.tp_dict,
&PyId___reduce__);
@@ -3976,16 +4051,49 @@
def __format__(self, format_spec):
return format(str(self), format_spec)
*/
+/*[clinic input]
+
+type.__format__
+
+ format_spec: unicode
+ /
+
+Default object formatter
+[clinic start generated code]*/
+
+PyDoc_STRVAR(type___format____doc__,
+"__format__(format_spec)\n"
+"Default object formatter");
+
+#define TYPE___FORMAT___METHODDEF \
+ {"__format__", (PyCFunction)type___format__, METH_VARARGS, type___format____doc__},
+
static PyObject *
-object_format(PyObject *self, PyObject *args)
-{
+type___format___impl(PyObject *self, PyObject *format_spec);
+
+static PyObject *
+type___format__(PyObject *self, PyObject *args)
+{
+ PyObject *return_value = NULL;
PyObject *format_spec;
+
+ if (!PyArg_ParseTuple(args,
+ "U:__format__",
+ &format_spec))
+ goto exit;
+ return_value = type___format___impl(self, format_spec);
+
+exit:
+ return return_value;
+}
+
+static PyObject *
+type___format___impl(PyObject *self, PyObject *format_spec)
+/*[clinic end generated code: checksum=a6b4ea69a30dd7c12c72bdf84ecda4235c427d1d]*/
+{
PyObject *self_as_str = NULL;
PyObject *result = NULL;
- if (!PyArg_ParseTuple(args, "U:__format__", &format_spec))
- return NULL;
-
self_as_str = PyObject_Str(self);
if (self_as_str != NULL) {
/* Issue 7994: If we're converting to a string, we
@@ -4067,14 +4175,11 @@
}
static PyMethodDef object_methods[] = {
- {"__reduce_ex__", object_reduce_ex, METH_VARARGS,
- PyDoc_STR("helper for pickle")},
- {"__reduce__", object_reduce, METH_VARARGS,
- PyDoc_STR("helper for pickle")},
+ TYPE___REDUCE_EX___METHODDEF
+ TYPE___REDUCE___METHODDEF
{"__subclasshook__", object_subclasshook, METH_CLASS | METH_VARARGS,
object_subclasshook_doc},
- {"__format__", object_format, METH_VARARGS,
- PyDoc_STR("default object formatter")},
+ TYPE___FORMAT___METHODDEF
{"__sizeof__", object_sizeof, METH_NOARGS,
PyDoc_STR("__sizeof__() -> int\nsize of object in memory, in bytes")},
{"__dir__", object_dir, METH_NOARGS,