FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-43163: Handle unclosed parentheses in codeop by pablogsal · Pull Request #24483 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
11 changes: 10 additions & 1 deletion Lib/codeop.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,20 @@ def _maybe_compile(compiler, source, filename, symbol):
try:
if code:
return code
Comment thread
terryjreedy marked this conversation as resolved.
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:
Comment thread
pablogsal marked this conversation as resolved.
return False
if rep1 == rep2:
return True
return False

def _compile(source, filename, symbol):
return compile(source, filename, symbol, PyCF_DONT_IMPLY_DEDENT)

Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_codeop.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ def test_incomplete(self):
ai("a = {")
ai("b + {")

ai("print([1,\n2,")
ai("print({1:1,\n2:3,")
ai("print((1,\n2,")

ai("if 9==3:\n pass\nelse:")
ai("if 9==3:\n pass\nelse:\n")
ai("if 9==3:\n pass\nelse:\n pass")
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a bug in :mod:`codeop` that was causing it to not ask for more input
when multi-line snippets have unclosed parentheses. Patch by Pablo Galindo

Back | FazBrowse Home | New Git URL