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 if (PyFloat_Check(args[2])) {
47 PyErr_SetString(PyExc_TypeError,
48 "integer argument expected, got float" );
49 goto exit;
50 }
51 {
52 Py_ssize_t ival = -1;
53 PyObject *iobj = PyNumber_Index(args[2]);
54 if (iobj != NULL) {
55 ival = PyLong_AsSsize_t(iobj);
56 Py_DECREF(iobj);
57 }
58 if (ival == -1 && PyErr_Occurred()) {
59 goto exit;
60 }
61 stacklevel = ival;
62 }
63 if (!--noptargs) {
64 goto skip_optional_pos;
65 }
66 }
67 source = args[3];
68 skip_optional_pos:
69 return_value = warnings_warn_impl(module, message, category, stacklevel, source);
70
71 exit:
72 return return_value;
73 }
74 /*[clinic end generated code: output=b7bb54c73b5433ec input=a9049054013a1b77]*/
75