gh-91102: Port 8-argument _warnings.warn_explicit to Argument Clinic (#92891)

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
This commit is contained in:
Oleg Iarygin 2022-07-20 23:24:51 +03:00 committed by GitHub
parent 6dadf6ca01
commit 41e0585ffa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 106 additions and 25 deletions

View file

@ -1030,28 +1030,31 @@ get_source_line(PyInterpreterState *interp, PyObject *module_globals, int lineno
return source_line;
}
/*[clinic input]
warn_explicit as warnings_warn_explicit
message: object
category: object
filename: unicode
lineno: int
module as mod: object = NULL
registry: object = None
module_globals: object = None
source as sourceobj: object = None
Issue a warning, or maybe ignore it or raise an exception.
[clinic start generated code]*/
static PyObject *
warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
warnings_warn_explicit_impl(PyObject *module, PyObject *message,
PyObject *category, PyObject *filename,
int lineno, PyObject *mod, PyObject *registry,
PyObject *module_globals, PyObject *sourceobj)
/*[clinic end generated code: output=c49c62b15a49a186 input=df6eeb8b45e712f1]*/
{
static char *kwd_list[] = {"message", "category", "filename", "lineno",
"module", "registry", "module_globals",
"source", 0};
PyObject *message;
PyObject *category;
PyObject *filename;
int lineno;
PyObject *module = NULL;
PyObject *registry = NULL;
PyObject *module_globals = NULL;
PyObject *sourceobj = NULL;
PyObject *source_line = NULL;
PyObject *returned;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOUi|OOOO:warn_explicit",
kwd_list, &message, &category, &filename, &lineno, &module,
&registry, &module_globals, &sourceobj))
return NULL;
PyThreadState *tstate = get_current_tstate();
if (tstate == NULL) {
return NULL;
@ -1070,8 +1073,8 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
return NULL;
}
}
returned = warn_explicit(tstate, category, message, filename, lineno, module,
registry, source_line, sourceobj);
returned = warn_explicit(tstate, category, message, filename, lineno,
mod, registry, source_line, sourceobj);
Py_XDECREF(source_line);
return returned;
}
@ -1331,13 +1334,9 @@ _PyErr_WarnUnawaitedCoroutine(PyObject *coro)
}
}
PyDoc_STRVAR(warn_explicit_doc,
"Low-level interface to warnings functionality.");
static PyMethodDef warnings_functions[] = {
WARNINGS_WARN_METHODDEF
{"warn_explicit", _PyCFunction_CAST(warnings_warn_explicit),
METH_VARARGS | METH_KEYWORDS, warn_explicit_doc},
WARNINGS_WARN_EXPLICIT_METHODDEF
{"_filters_mutated", _PyCFunction_CAST(warnings_filters_mutated), METH_NOARGS,
NULL},
/* XXX(brett.cannon): add showwarning? */