gh-135801: Add the module parameter to compile() etc (GH-139652)

Many functions related to compiling or parsing Python code, such as
compile(), ast.parse(), symtable.symtable(),
and importlib.abc.InspectLoader.source_to_code() now allow to pass
the module name used when filtering syntax warnings.
This commit is contained in:
Serhiy Storchaka 2025-11-13 13:21:32 +02:00 committed by GitHub
parent 63548b3699
commit d8e6bdc0d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
47 changed files with 390 additions and 115 deletions

View file

@ -1960,10 +1960,11 @@ _PyErr_RaiseSyntaxError(PyObject *msg, PyObject *filename, int lineno, int col_o
*/
int
_PyErr_EmitSyntaxWarning(PyObject *msg, PyObject *filename, int lineno, int col_offset,
int end_lineno, int end_col_offset)
int end_lineno, int end_col_offset,
PyObject *module)
{
if (PyErr_WarnExplicitObject(PyExc_SyntaxWarning, msg,
filename, lineno, NULL, NULL) < 0)
if (PyErr_WarnExplicitObject(PyExc_SyntaxWarning, msg, filename, lineno,
module, NULL) < 0)
{
if (PyErr_ExceptionMatches(PyExc_SyntaxWarning)) {
/* Replace the SyntaxWarning exception with a SyntaxError