1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 # include "pycore_gc.h" // PyGC_Head
7 # include "pycore_runtime.h" // _Py_ID()
8 #endif
9
10
11 PyDoc_STRVAR(module___init____doc__,
12 "module(name, doc=None)\n"
13 "--\n"
14 "\n"
15 "Create a module object.\n"
16 "\n"
17 "The name must be a string; the optional doc argument can have any type.");
18
19 static int
20 module___init___impl(PyModuleObject *self, PyObject *name, PyObject *doc);
21
22 static int
23 module___init__(PyObject *self, PyObject *args, PyObject *kwargs)
24 {
25 int return_value = -1;
26 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
27
28 #define NUM_KEYWORDS 2
29 static struct {
30 PyGC_Head _this_is_not_used;
31 PyObject_VAR_HEAD
32 PyObject *ob_item[NUM_KEYWORDS];
33 } _kwtuple = {
34 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
35 .ob_item = { &_Py_ID(name), &_Py_ID(doc), },
36 };
37 #undef NUM_KEYWORDS
38 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
39
40 #else // !Py_BUILD_CORE
41 # define KWTUPLE NULL
42 #endif // !Py_BUILD_CORE
43
44 static const char * const _keywords[] = {"name", "doc", NULL};
45 static _PyArg_Parser _parser = {
46 .keywords = _keywords,
47 .fname = "module",
48 .kwtuple = KWTUPLE,
49 };
50 #undef KWTUPLE
51 PyObject *argsbuf[2];
52 PyObject * const *fastargs;
53 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
54 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
55 PyObject *name;
56 PyObject *doc = Py_None;
57
58 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
59 if (!fastargs) {
60 goto exit;
61 }
62 if (!PyUnicode_Check(fastargs[0])) {
63 _PyArg_BadArgument("module", "argument 'name'", "str", fastargs[0]);
64 goto exit;
65 }
66 if (PyUnicode_READY(fastargs[0]) == -1) {
67 goto exit;
68 }
69 name = fastargs[0];
70 if (!noptargs) {
71 goto skip_optional_pos;
72 }
73 doc = fastargs[1];
74 skip_optional_pos:
75 return_value = module___init___impl((PyModuleObject *)self, name, doc);
76
77 exit:
78 return return_value;
79 }
80 /*[clinic end generated code: output=2f897c9e4721f03f input=a9049054013a1b77]*/