mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
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:
parent
63548b3699
commit
d8e6bdc0d0
47 changed files with 390 additions and 115 deletions
|
|
@ -16,6 +16,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
PyObject *filename;
|
||||
PyObject *module;
|
||||
int optimize;
|
||||
int ff_features;
|
||||
int syntax_check_only;
|
||||
|
|
@ -71,7 +72,8 @@ control_flow_in_finally_warning(const char *kw, stmt_ty n, _PyASTPreprocessState
|
|||
}
|
||||
int ret = _PyErr_EmitSyntaxWarning(msg, state->filename, n->lineno,
|
||||
n->col_offset + 1, n->end_lineno,
|
||||
n->end_col_offset + 1);
|
||||
n->end_col_offset + 1,
|
||||
state->module);
|
||||
Py_DECREF(msg);
|
||||
return ret < 0 ? 0 : 1;
|
||||
}
|
||||
|
|
@ -969,11 +971,13 @@ astfold_type_param(type_param_ty node_, PyArena *ctx_, _PyASTPreprocessState *st
|
|||
|
||||
int
|
||||
_PyAST_Preprocess(mod_ty mod, PyArena *arena, PyObject *filename, int optimize,
|
||||
int ff_features, int syntax_check_only, int enable_warnings)
|
||||
int ff_features, int syntax_check_only, int enable_warnings,
|
||||
PyObject *module)
|
||||
{
|
||||
_PyASTPreprocessState state;
|
||||
memset(&state, 0, sizeof(_PyASTPreprocessState));
|
||||
state.filename = filename;
|
||||
state.module = module;
|
||||
state.optimize = optimize;
|
||||
state.ff_features = ff_features;
|
||||
state.syntax_check_only = syntax_check_only;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue