bpo-43163: Handle unclosed parentheses in codeop (GH-24483)

This commit is contained in:
Pablo Galindo 2021-02-09 20:07:38 +00:00 committed by GitHub
parent b74396c316
commit dbb228189b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View file

@ -102,11 +102,20 @@ def _maybe_compile(compiler, source, filename, symbol):
try:
if code:
return code
if not code1 and repr(err1) == repr(err2):
if not code1 and _is_syntax_error(err1, err2):
raise err1
finally:
err1 = err2 = None
def _is_syntax_error(err1, err2):
rep1 = repr(err1)
rep2 = repr(err2)
if "was never closed" in rep1 and "was never closed" in rep2:
return False
if rep1 == rep2:
return True
return False
def _compile(source, filename, symbol):
return compile(source, filename, symbol, PyCF_DONT_IMPLY_DEDENT)