Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-40585: Normalize errors messages in codeop when comparing them #20030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-40585: Normalize errors messages in codeop when comparing them
With the new parser, the error message contains always the trailing
newlines, causing the naive comparison of the repr of the error messages
in codeop to fail.
  • Loading branch information
pablogsal committed May 10, 2020
commit de6892a3cc04bdefb2376a912af9685d88432fd9
5 changes: 4 additions & 1 deletion 5 Lib/codeop.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ def _maybe_compile(compiler, source, filename, symbol):
except SyntaxError as e:
err2 = e

def normalize_error(err):
return repr(err).replace("\\n", "")

try:
if code:
return code
if not code1 and repr(err1) == repr(err2):
if not code1 and normalize_error(err1) == normalize_error(err2):
raise err1
finally:
err1 = err2 = None
Expand Down
9 changes: 9 additions & 0 deletions 9 Lib/test/test_codeop.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,15 @@ def test_invalid(self):

ai("[i for i in range(10)] = (1, 2, 3)")

def test_invalid_exec(self):
ai = self.assertInvalid
ai("raise = 4", symbol="exec")
ai('def a-b', symbol='exec')
ai('await?', symbol='exec')
ai('=!=', symbol='exec')
ai('a await raise b', symbol='exec')
ai('a await raise b?+1', symbol='exec')

def test_filename(self):
self.assertEqual(compile_command("a = 1\n", "abc").co_filename,
compile("a = 1\n", "abc", 'single').co_filename)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed a bug when using :func:`codeop.compile_command` that was causing
exceptions to be swallowed with the new parser. Patch by Pablo Galindo
Morty Proxy This is a proxified and sanitized view of the page, visit original site.