1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 PyDoc_STRVAR(complex_new__doc__,
6 "complex(real=0, imag=0)\n"
7 "--\n"
8 "\n"
9 "Create a complex number from a real part and an optional imaginary part.\n"
10 "\n"
11 "This is equivalent to (real + imag*1j) where imag defaults to 0.");
12 
13 static PyObject *
14 complex_new_impl(PyTypeObject *type, PyObject *r, PyObject *i);
15 
16 static PyObject *
complex_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)17 complex_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
18 {
19     PyObject *return_value = NULL;
20     static const char * const _keywords[] = {"real", "imag", NULL};
21     static _PyArg_Parser _parser = {NULL, _keywords, "complex", 0};
22     PyObject *argsbuf[2];
23     PyObject * const *fastargs;
24     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
25     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
26     PyObject *r = _PyLong_Zero;
27     PyObject *i = NULL;
28 
29     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf);
30     if (!fastargs) {
31         goto exit;
32     }
33     if (!noptargs) {
34         goto skip_optional_pos;
35     }
36     if (fastargs[0]) {
37         r = fastargs[0];
38         if (!--noptargs) {
39             goto skip_optional_pos;
40         }
41     }
42     i = fastargs[1];
43 skip_optional_pos:
44     return_value = complex_new_impl(type, r, i);
45 
46 exit:
47     return return_value;
48 }
49 /*[clinic end generated code: output=a0fe23fdbdc9b06b input=a9049054013a1b77]*/
50