• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 PyDoc_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)(void(*)(void))warnings_warn, METH_FASTCALL|METH_KEYWORDS, warnings_warn__doc__},
13 
14 static PyObject *
15 warnings_warn_impl(PyObject *module, PyObject *message, PyObject *category,
16                    Py_ssize_t stacklevel, PyObject *source);
17 
18 static PyObject *
warnings_warn(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)19 warnings_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];
63 skip_optional_pos:
64     return_value = warnings_warn_impl(module, message, category, stacklevel, source);
65 
66 exit:
67     return return_value;
68 }
69 /*[clinic end generated code: output=eb9997fa998fdbad input=a9049054013a1b77]*/
70