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 #include "pycore_abstract.h" // _PyNumber_Index()
10 #include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
11
12 PyDoc_STRVAR(warnings_warn__doc__,
13 "warn($module, /, message, category=None, stacklevel=1, source=None, *,\n"
14 " skip_file_prefixes=<unrepresentable>)\n"
15 "--\n"
16 "\n"
17 "Issue a warning, or maybe ignore it or raise an exception.\n"
18 "\n"
19 " message\n"
20 " Text of the warning message.\n"
21 " category\n"
22 " The Warning category subclass. Defaults to UserWarning.\n"
23 " stacklevel\n"
24 " How far up the call stack to make this warning appear. A value of 2 for\n"
25 " example attributes the warning to the caller of the code calling warn().\n"
26 " source\n"
27 " If supplied, the destroyed object which emitted a ResourceWarning\n"
28 " skip_file_prefixes\n"
29 " An optional tuple of module filename prefixes indicating frames to skip\n"
30 " during stacklevel computations for stack frame attribution.");
31
32 #define WARNINGS_WARN_METHODDEF \
33 {"warn", _PyCFunction_CAST(warnings_warn), METH_FASTCALL|METH_KEYWORDS, warnings_warn__doc__},
34
35 static PyObject *
36 warnings_warn_impl(PyObject *module, PyObject *message, PyObject *category,
37 Py_ssize_t stacklevel, PyObject *source,
38 PyTupleObject *skip_file_prefixes);
39
40 static PyObject *
warnings_warn(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)41 warnings_warn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
42 {
43 PyObject *return_value = NULL;
44 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
45
46 #define NUM_KEYWORDS 5
47 static struct {
48 PyGC_Head _this_is_not_used;
49 PyObject_VAR_HEAD
50 PyObject *ob_item[NUM_KEYWORDS];
51 } _kwtuple = {
52 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
53 .ob_item = { &_Py_ID(message), &_Py_ID(category), &_Py_ID(stacklevel), &_Py_ID(source), &_Py_ID(skip_file_prefixes), },
54 };
55 #undef NUM_KEYWORDS
56 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
57
58 #else // !Py_BUILD_CORE
59 # define KWTUPLE NULL
60 #endif // !Py_BUILD_CORE
61
62 static const char * const _keywords[] = {"message", "category", "stacklevel", "source", "skip_file_prefixes", NULL};
63 static _PyArg_Parser _parser = {
64 .keywords = _keywords,
65 .fname = "warn",
66 .kwtuple = KWTUPLE,
67 };
68 #undef KWTUPLE
69 PyObject *argsbuf[5];
70 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
71 PyObject *message;
72 PyObject *category = Py_None;
73 Py_ssize_t stacklevel = 1;
74 PyObject *source = Py_None;
75 PyTupleObject *skip_file_prefixes = NULL;
76
77 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 4, 0, argsbuf);
78 if (!args) {
79 goto exit;
80 }
81 message = args[0];
82 if (!noptargs) {
83 goto skip_optional_pos;
84 }
85 if (args[1]) {
86 category = args[1];
87 if (!--noptargs) {
88 goto skip_optional_pos;
89 }
90 }
91 if (args[2]) {
92 {
93 Py_ssize_t ival = -1;
94 PyObject *iobj = _PyNumber_Index(args[2]);
95 if (iobj != NULL) {
96 ival = PyLong_AsSsize_t(iobj);
97 Py_DECREF(iobj);
98 }
99 if (ival == -1 && PyErr_Occurred()) {
100 goto exit;
101 }
102 stacklevel = ival;
103 }
104 if (!--noptargs) {
105 goto skip_optional_pos;
106 }
107 }
108 if (args[3]) {
109 source = args[3];
110 if (!--noptargs) {
111 goto skip_optional_pos;
112 }
113 }
114 skip_optional_pos:
115 if (!noptargs) {
116 goto skip_optional_kwonly;
117 }
118 if (!PyTuple_Check(args[4])) {
119 _PyArg_BadArgument("warn", "argument 'skip_file_prefixes'", "tuple", args[4]);
120 goto exit;
121 }
122 skip_file_prefixes = (PyTupleObject *)args[4];
123 skip_optional_kwonly:
124 return_value = warnings_warn_impl(module, message, category, stacklevel, source, skip_file_prefixes);
125
126 exit:
127 return return_value;
128 }
129
130 PyDoc_STRVAR(warnings_warn_explicit__doc__,
131 "warn_explicit($module, /, message, category, filename, lineno,\n"
132 " module=<unrepresentable>, registry=None,\n"
133 " module_globals=None, source=None)\n"
134 "--\n"
135 "\n"
136 "Issue a warning, or maybe ignore it or raise an exception.");
137
138 #define WARNINGS_WARN_EXPLICIT_METHODDEF \
139 {"warn_explicit", _PyCFunction_CAST(warnings_warn_explicit), METH_FASTCALL|METH_KEYWORDS, warnings_warn_explicit__doc__},
140
141 static PyObject *
142 warnings_warn_explicit_impl(PyObject *module, PyObject *message,
143 PyObject *category, PyObject *filename,
144 int lineno, PyObject *mod, PyObject *registry,
145 PyObject *module_globals, PyObject *sourceobj);
146
147 static PyObject *
warnings_warn_explicit(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)148 warnings_warn_explicit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
149 {
150 PyObject *return_value = NULL;
151 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
152
153 #define NUM_KEYWORDS 8
154 static struct {
155 PyGC_Head _this_is_not_used;
156 PyObject_VAR_HEAD
157 PyObject *ob_item[NUM_KEYWORDS];
158 } _kwtuple = {
159 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
160 .ob_item = { &_Py_ID(message), &_Py_ID(category), &_Py_ID(filename), &_Py_ID(lineno), &_Py_ID(module), &_Py_ID(registry), &_Py_ID(module_globals), &_Py_ID(source), },
161 };
162 #undef NUM_KEYWORDS
163 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
164
165 #else // !Py_BUILD_CORE
166 # define KWTUPLE NULL
167 #endif // !Py_BUILD_CORE
168
169 static const char * const _keywords[] = {"message", "category", "filename", "lineno", "module", "registry", "module_globals", "source", NULL};
170 static _PyArg_Parser _parser = {
171 .keywords = _keywords,
172 .fname = "warn_explicit",
173 .kwtuple = KWTUPLE,
174 };
175 #undef KWTUPLE
176 PyObject *argsbuf[8];
177 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
178 PyObject *message;
179 PyObject *category;
180 PyObject *filename;
181 int lineno;
182 PyObject *mod = NULL;
183 PyObject *registry = Py_None;
184 PyObject *module_globals = Py_None;
185 PyObject *sourceobj = Py_None;
186
187 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 8, 0, argsbuf);
188 if (!args) {
189 goto exit;
190 }
191 message = args[0];
192 category = args[1];
193 if (!PyUnicode_Check(args[2])) {
194 _PyArg_BadArgument("warn_explicit", "argument 'filename'", "str", args[2]);
195 goto exit;
196 }
197 filename = args[2];
198 lineno = PyLong_AsInt(args[3]);
199 if (lineno == -1 && PyErr_Occurred()) {
200 goto exit;
201 }
202 if (!noptargs) {
203 goto skip_optional_pos;
204 }
205 if (args[4]) {
206 mod = args[4];
207 if (!--noptargs) {
208 goto skip_optional_pos;
209 }
210 }
211 if (args[5]) {
212 registry = args[5];
213 if (!--noptargs) {
214 goto skip_optional_pos;
215 }
216 }
217 if (args[6]) {
218 module_globals = args[6];
219 if (!--noptargs) {
220 goto skip_optional_pos;
221 }
222 }
223 sourceobj = args[7];
224 skip_optional_pos:
225 return_value = warnings_warn_explicit_impl(module, message, category, filename, lineno, mod, registry, module_globals, sourceobj);
226
227 exit:
228 return return_value;
229 }
230
231 PyDoc_STRVAR(warnings_filters_mutated__doc__,
232 "_filters_mutated($module, /)\n"
233 "--\n"
234 "\n");
235
236 #define WARNINGS_FILTERS_MUTATED_METHODDEF \
237 {"_filters_mutated", (PyCFunction)warnings_filters_mutated, METH_NOARGS, warnings_filters_mutated__doc__},
238
239 static PyObject *
240 warnings_filters_mutated_impl(PyObject *module);
241
242 static PyObject *
warnings_filters_mutated(PyObject * module,PyObject * Py_UNUSED (ignored))243 warnings_filters_mutated(PyObject *module, PyObject *Py_UNUSED(ignored))
244 {
245 return warnings_filters_mutated_impl(module);
246 }
247 /*[clinic end generated code: output=f2d4214c382717a6 input=a9049054013a1b77]*/
248