Debian Codegraph @

Python/clinic/_warnings.c.h

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