summaryrefslogtreecommitdiffstats
path: root/Objects/clinic
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-03-19 06:51:07 (GMT)
committerGitHub <noreply@github.com>2017-03-19 06:51:07 (GMT)
commit18b250f844bf8b2d1a81c2d2dcc74e850364fe35 (patch)
tree117c9240b5b87067a07cb43bc9260ed26c3148bb /Objects/clinic
parent0b5615926a573c19c887a701a2f7047f4fd06de6 (diff)
downloadcpython-18b250f844bf8b2d1a81c2d2dcc74e850364fe35.zip
cpython-18b250f844bf8b2d1a81c2d2dcc74e850364fe35.tar.gz
cpython-18b250f844bf8b2d1a81c2d2dcc74e850364fe35.tar.bz2
bpo-29793: Convert some builtin types constructors to Argument Clinic. (#615)
Diffstat (limited to 'Objects/clinic')
-rw-r--r--Objects/clinic/complexobject.c.h34
-rw-r--r--Objects/clinic/descrobject.c.h87
-rw-r--r--Objects/clinic/floatobject.c.h32
-rw-r--r--Objects/clinic/funcobject.c.h47
-rw-r--r--Objects/clinic/longobject.c.h24
-rw-r--r--Objects/clinic/moduleobject.c.h34
-rw-r--r--Objects/clinic/structseq.c.h26
7 files changed, 282 insertions, 2 deletions
diff --git a/Objects/clinic/complexobject.c.h b/Objects/clinic/complexobject.c.h
new file mode 100644
index 0000000..b0b4c0e
--- /dev/null
+++ b/Objects/clinic/complexobject.c.h
@@ -0,0 +1,34 @@
+/*[clinic input]
+preserve
+[clinic start generated code]*/
+
+PyDoc_STRVAR(complex_new__doc__,
+"complex(real=0, imag=0)\n"
+"--\n"
+"\n"
+"Create a complex number from a real part and an optional imaginary part.\n"
+"\n"
+"This is equivalent to (real + imag*1j) where imag defaults to 0.");
+
+static PyObject *
+complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i);
+
+static PyObject *
+complex_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+{
+ PyObject *return_value = NULL;
+ static const char * const _keywords[] = {"real", "imag", NULL};
+ static _PyArg_Parser _parser = {"|OO:complex", _keywords, 0};
+ PyObject *r = Py_False;
+ PyObject *i = NULL;
+
+ if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
+ &r, &i)) {
+ goto exit;
+ }
+ return_value = complex_new_impl(type, r, i);
+
+exit:
+ return return_value;
+}
+/*[clinic end generated code: output=74035493480ab5e5 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/descrobject.c.h b/Objects/clinic/descrobject.c.h
new file mode 100644
index 0000000..71b1966
--- /dev/null
+++ b/Objects/clinic/descrobject.c.h
@@ -0,0 +1,87 @@
+/*[clinic input]
+preserve
+[clinic start generated code]*/
+
+static PyObject *
+mappingproxy_new_impl(PyTypeObject *type, PyObject *mapping);
+
+static PyObject *
+mappingproxy_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+{
+ PyObject *return_value = NULL;
+ static const char * const _keywords[] = {"mapping", NULL};
+ static _PyArg_Parser _parser = {"O:mappingproxy", _keywords, 0};
+ PyObject *mapping;
+
+ if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
+ &mapping)) {
+ goto exit;
+ }
+ return_value = mappingproxy_new_impl(type, mapping);
+
+exit:
+ return return_value;
+}
+
+PyDoc_STRVAR(property_init__doc__,
+"property(fget=None, fset=None, fdel=None, doc=None)\n"
+"--\n"
+"\n"
+"Property attribute.\n"
+"\n"
+" fget\n"
+" function to be used for getting an attribute value\n"
+" fset\n"
+" function to be used for setting an attribute value\n"
+" fdel\n"
+" function to be used for del\'ing an attribute\n"
+" doc\n"
+" docstring\n"
+"\n"
+"Typical use is to define a managed attribute x:\n"
+"\n"
+"class C(object):\n"
+" def getx(self): return self._x\n"
+" def setx(self, value): self._x = value\n"
+" def delx(self): del self._x\n"
+" x = property(getx, setx, delx, \"I\'m the \'x\' property.\")\n"
+"\n"
+"Decorators make defining new properties or modifying existing ones easy:\n"
+"\n"
+"class C(object):\n"
+" @property\n"
+" def x(self):\n"
+" \"I am the \'x\' property.\"\n"
+" return self._x\n"
+" @x.setter\n"
+" def x(self, value):\n"
+" self._x = value\n"
+" @x.deleter\n"
+" def x(self):\n"
+" del self._x");
+
+static int
+property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset,
+ PyObject *fdel, PyObject *doc);
+
+static int
+property_init(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ int return_value = -1;
+ static const char * const _keywords[] = {"fget", "fset", "fdel", "doc", NULL};
+ static _PyArg_Parser _parser = {"|OOOO:property", _keywords, 0};
+ PyObject *fget = NULL;
+ PyObject *fset = NULL;
+ PyObject *fdel = NULL;
+ PyObject *doc = NULL;
+
+ if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
+ &fget, &fset, &fdel, &doc)) {
+ goto exit;
+ }
+ return_value = property_init_impl((propertyobject *)self, fget, fset, fdel, doc);
+
+exit:
+ return return_value;
+}
+/*[clinic end generated code: output=729021fa9cdc46be input=a9049054013a1b77]*/
diff --git a/Objects/clinic/floatobject.c.h b/Objects/clinic/floatobject.c.h
index 18c6918..d2680b5 100644
--- a/Objects/clinic/floatobject.c.h
+++ b/Objects/clinic/floatobject.c.h
@@ -158,6 +158,36 @@ float_as_integer_ratio(PyObject *self, PyObject *Py_UNUSED(ignored))
return float_as_integer_ratio_impl(self);
}
+PyDoc_STRVAR(float_new__doc__,
+"float(x=0, /)\n"
+"--\n"
+"\n"
+"Convert a string or number to a floating point number, if possible.");
+
+static PyObject *
+float_new_impl(PyTypeObject *type, PyObject *x);
+
+static PyObject *
+float_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+{
+ PyObject *return_value = NULL;
+ PyObject *x = Py_False;
+
+ if ((type == &PyFloat_Type) &&
+ !_PyArg_NoKeywords("float", kwargs)) {
+ goto exit;
+ }
+ if (!PyArg_UnpackTuple(args, "float",
+ 0, 1,
+ &x)) {
+ goto exit;
+ }
+ return_value = float_new_impl(type, x);
+
+exit:
+ return return_value;
+}
+
PyDoc_STRVAR(float___getnewargs____doc__,
"__getnewargs__($self, /)\n"
"--\n"
@@ -283,4 +313,4 @@ float___format__(PyObject *self, PyObject *arg)
exit:
return return_value;
}
-/*[clinic end generated code: output=9257442b321d6a8b input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a3dafb0f6c6f1514 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/funcobject.c.h b/Objects/clinic/funcobject.c.h
new file mode 100644
index 0000000..4c54483
--- /dev/null
+++ b/Objects/clinic/funcobject.c.h
@@ -0,0 +1,47 @@
+/*[clinic input]
+preserve
+[clinic start generated code]*/
+
+PyDoc_STRVAR(func_new__doc__,
+"function(code, globals, name=None, argdefs=None, closure=None)\n"
+"--\n"
+"\n"
+"Create a function object.\n"
+"\n"
+" code\n"
+" a code object\n"
+" globals\n"
+" the globals dictionary\n"
+" name\n"
+" a string that overrides the name from the code object\n"
+" argdefs\n"
+" a tuple that specifies the default argument values\n"
+" closure\n"
+" a tuple that supplies the bindings for free variables");
+
+static PyObject *
+func_new_impl(PyTypeObject *type, PyCodeObject *code, PyObject *globals,
+ PyObject *name, PyObject *defaults, PyObject *closure);
+
+static PyObject *
+func_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+{
+ PyObject *return_value = NULL;
+ static const char * const _keywords[] = {"code", "globals", "name", "argdefs", "closure", NULL};
+ static _PyArg_Parser _parser = {"O!O!|OOO:function", _keywords, 0};
+ PyCodeObject *code;
+ PyObject *globals;
+ PyObject *name = Py_None;
+ PyObject *defaults = Py_None;
+ PyObject *closure = Py_None;
+
+ if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
+ &PyCode_Type, &code, &PyDict_Type, &globals, &name, &defaults, &closure)) {
+ goto exit;
+ }
+ return_value = func_new_impl(type, code, globals, name, defaults, closure);
+
+exit:
+ return return_value;
+}
+/*[clinic end generated code: output=a6ab29e4dd33010a input=a9049054013a1b77]*/
diff --git a/Objects/clinic/longobject.c.h b/Objects/clinic/longobject.c.h
index 6a7b7de..81bc97f 100644
--- a/Objects/clinic/longobject.c.h
+++ b/Objects/clinic/longobject.c.h
@@ -2,6 +2,28 @@
preserve
[clinic start generated code]*/
+static PyObject *
+long_new_impl(PyTypeObject *type, PyObject *x, PyObject *obase);
+
+static PyObject *
+long_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+{
+ PyObject *return_value = NULL;
+ static const char * const _keywords[] = {"", "base", NULL};
+ static _PyArg_Parser _parser = {"|OO:int", _keywords, 0};
+ PyObject *x = NULL;
+ PyObject *obase = NULL;
+
+ if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
+ &x, &obase)) {
+ goto exit;
+ }
+ return_value = long_new_impl(type, x, obase);
+
+exit:
+ return return_value;
+}
+
PyDoc_STRVAR(int___getnewargs____doc__,
"__getnewargs__($self, /)\n"
"--\n"
@@ -189,4 +211,4 @@ int_from_bytes(PyTypeObject *type, PyObject **args, Py_ssize_t nargs, PyObject *
exit:
return return_value;
}
-/*[clinic end generated code: output=a9bae2fd016e7b85 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=c1ce9c11929b0bab input=a9049054013a1b77]*/
diff --git a/Objects/clinic/moduleobject.c.h b/Objects/clinic/moduleobject.c.h
new file mode 100644
index 0000000..e841e76
--- /dev/null
+++ b/Objects/clinic/moduleobject.c.h
@@ -0,0 +1,34 @@
+/*[clinic input]
+preserve
+[clinic start generated code]*/
+
+PyDoc_STRVAR(module___init____doc__,
+"module(name, doc=None)\n"
+"--\n"
+"\n"
+"Create a module object.\n"
+"\n"
+"The name must be a string; the optional doc argument can have any type.");
+
+static int
+module___init___impl(PyModuleObject *self, PyObject *name, PyObject *doc);
+
+static int
+module___init__(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ int return_value = -1;
+ static const char * const _keywords[] = {"name", "doc", NULL};
+ static _PyArg_Parser _parser = {"U|O:module", _keywords, 0};
+ PyObject *name;
+ PyObject *doc = Py_None;
+
+ if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
+ &name, &doc)) {
+ goto exit;
+ }
+ return_value = module___init___impl((PyModuleObject *)self, name, doc);
+
+exit:
+ return return_value;
+}
+/*[clinic end generated code: output=7b1b324bf6a590d1 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/structseq.c.h b/Objects/clinic/structseq.c.h
new file mode 100644
index 0000000..ed6a564
--- /dev/null
+++ b/Objects/clinic/structseq.c.h
@@ -0,0 +1,26 @@
+/*[clinic input]
+preserve
+[clinic start generated code]*/
+
+static PyObject *
+structseq_new_impl(PyTypeObject *type, PyObject *arg, PyObject *dict);
+
+static PyObject *
+structseq_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+{
+ PyObject *return_value = NULL;
+ static const char * const _keywords[] = {"sequence", "dict", NULL};
+ static _PyArg_Parser _parser = {"O|O:structseq", _keywords, 0};
+ PyObject *arg;
+ PyObject *dict = NULL;
+
+ if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
+ &arg, &dict)) {
+ goto exit;
+ }
+ return_value = structseq_new_impl(type, arg, dict);
+
+exit:
+ return return_value;
+}
+/*[clinic end generated code: output=cd643eb89b5d312a input=a9049054013a1b77]*/