1/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(warnings_warn__doc__,
6"warn($module, /, message, category=None, stacklevel=1, source=None)\n"
7"--\n"
8"\n"
9"Issue a warning, or maybe ignore it or raise an exception.");
10
11#define WARNINGS_WARN_METHODDEF    \
12    {"warn", _PyCFunction_CAST(warnings_warn), METH_FASTCALL|METH_KEYWORDS, warnings_warn__doc__},
13
14static PyObject *
15warnings_warn_impl(PyObject *module, PyObject *message, PyObject *category,
16                   Py_ssize_t stacklevel, PyObject *source);
17
18static PyObject *
19warnings_warn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
20{
21    PyObject *return_value = NULL;
22    static const char * const _keywords[] = {"message", "category", "stacklevel", "source", NULL};
23    static _PyArg_Parser _parser = {NULL, _keywords, "warn", 0};
24    PyObject *argsbuf[4];
25    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
26    PyObject *message;
27    PyObject *category = Py_None;
28    Py_ssize_t stacklevel = 1;
29    PyObject *source = Py_None;
30
31    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 4, 0, argsbuf);
32    if (!args) {
33        goto exit;
34    }
35    message = args[0];
36    if (!noptargs) {
37        goto skip_optional_pos;
38    }
39    if (args[1]) {
40        category = args[1];
41        if (!--noptargs) {
42            goto skip_optional_pos;
43        }
44    }
45    if (args[2]) {
46        {
47            Py_ssize_t ival = -1;
48            PyObject *iobj = _PyNumber_Index(args[2]);
49            if (iobj != NULL) {
50                ival = PyLong_AsSsize_t(iobj);
51                Py_DECREF(iobj);
52            }
53            if (ival == -1 && PyErr_Occurred()) {
54                goto exit;
55            }
56            stacklevel = ival;
57        }
58        if (!--noptargs) {
59            goto skip_optional_pos;
60        }
61    }
62    source = args[3];
63skip_optional_pos:
64    return_value = warnings_warn_impl(module, message, category, stacklevel, source);
65
66exit:
67    return return_value;
68}
69/*[clinic end generated code: output=0435c68611fa2fe9 input=a9049054013a1b77]*/
70