diff options
author | Pablo Galindo Salgado <Pablogsal@gmail.com> | 2023-10-30 19:24:21 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-30 19:24:21 +0000 |
commit | cd6e0a04a16535d8bc727c84f73730c53267184e (patch) | |
tree | f3df1c90e9cf0fd082ba478174fde12ebb107dc5 /Lib/codeop.py | |
parent | 624ace5a2f02715d084c29eaf2211cd0dd550690 (diff) | |
download | cpython-cd6e0a04a16535d8bc727c84f73730c53267184e.tar.gz cpython-cd6e0a04a16535d8bc727c84f73730c53267184e.zip |
gh-111366: Correctly show custom syntax error messages in the codeop module functions (#111384)
Diffstat (limited to 'Lib/codeop.py')
-rw-r--r-- | Lib/codeop.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Lib/codeop.py b/Lib/codeop.py index a574aa4b70f..91146be2c43 100644 --- a/Lib/codeop.py +++ b/Lib/codeop.py @@ -70,10 +70,14 @@ def _maybe_compile(compiler, source, filename, symbol): return None # fallthrough - return compiler(source, filename, symbol) + return compiler(source, filename, symbol, incomplete_input=False) -def _compile(source, filename, symbol): - return compile(source, filename, symbol, PyCF_DONT_IMPLY_DEDENT | PyCF_ALLOW_INCOMPLETE_INPUT) +def _compile(source, filename, symbol, incomplete_input=True): + flags = 0 + if incomplete_input: + flags |= PyCF_ALLOW_INCOMPLETE_INPUT + flags |= PyCF_DONT_IMPLY_DEDENT + return compile(source, filename, symbol, flags) def compile_command(source, filename="<input>", symbol="single"): r"""Compile a command and determine whether it is incomplete. @@ -104,8 +108,12 @@ class Compile: def __init__(self): self.flags = PyCF_DONT_IMPLY_DEDENT | PyCF_ALLOW_INCOMPLETE_INPUT - def __call__(self, source, filename, symbol): - codeob = compile(source, filename, symbol, self.flags, True) + def __call__(self, source, filename, symbol, **kwargs): + flags = self.flags + if kwargs.get('incomplete_input', True) is False: + flags &= ~PyCF_DONT_IMPLY_DEDENT + flags &= ~PyCF_ALLOW_INCOMPLETE_INPUT + codeob = compile(source, filename, symbol, flags, True) for feature in _features: if codeob.co_flags & feature.compiler_flag: self.flags |= feature.compiler_flag |