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