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
|
|
@ -182,7 +182,7 @@ def _execute_script(script_path: str, script_args: List[str], cwd: str) -> None:
|
|||
|
||||
try:
|
||||
# Compile and execute the script
|
||||
code = compile(source_code, script_path, 'exec')
|
||||
code = compile(source_code, script_path, 'exec', module='__main__')
|
||||
exec(code, {'__name__': '__main__', '__file__': script_path})
|
||||
except SyntaxError as e:
|
||||
raise TargetError(f"Syntax error in script {script_path}: {e}") from e
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue