summaryrefslogtreecommitdiffstats
path: root/Lib/codeop.py
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2023-10-31 14:41:20 (GMT)
committerGitHub <noreply@github.com>2023-10-31 14:41:20 (GMT)
commit19a266ca8961d8dcb85799adb1025e4f4fb2f087 (patch)
tree2257324a9b2e21ce7e3f447b12e3eaf86db88198 /Lib/codeop.py
parentbc9f47097ef5c44c87cb91a441c19ee532907684 (diff)
downloadcpython-19a266ca8961d8dcb85799adb1025e4f4fb2f087.zip
cpython-19a266ca8961d8dcb85799adb1025e4f4fb2f087.tar.gz
cpython-19a266ca8961d8dcb85799adb1025e4f4fb2f087.tar.bz2
[3.11] gh-111366: Correctly show custom syntax error messages in the codeop module functions (GH-111384). (#111516)
(cherry picked from commit cd6e0a04a16535d8bc727c84f73730c53267184e)
Diffstat (limited to 'Lib/codeop.py')
-rw-r--r--Lib/codeop.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/Lib/codeop.py b/Lib/codeop.py
index 2213b69..e64911e 100644
--- a/Lib/codeop.py
+++ b/Lib/codeop.py
@@ -70,8 +70,7 @@ def _maybe_compile(compiler, source, filename, symbol):
return None
# fallthrough
- return compiler(source, filename, symbol)
-
+ return compiler(source, filename, symbol, incomplete_input=False)
def _is_syntax_error(err1, err2):
rep1 = repr(err1)
@@ -82,8 +81,12 @@ def _is_syntax_error(err1, err2):
return True
return 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.
@@ -114,8 +117,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