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

[3.12] gh-116034: fix location info on the error of a failed assertion #116054

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 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion 2 Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ def test_multiline_assert(self):
self.assertOpcodeSourcePositionIs(compiled_code, 'CALL',
line=1, end_line=3, column=0, end_column=30, occurrence=1)
self.assertOpcodeSourcePositionIs(compiled_code, 'RAISE_VARARGS',
line=1, end_line=3, column=0, end_column=30, occurrence=1)
line=1, end_line=3, column=8, end_column=16, occurrence=1)

def test_multiline_generator_expression(self):
snippet = textwrap.dedent("""\
Expand Down
17 changes: 17 additions & 0 deletions 17 Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,23 @@ def f_with_binary_operator():
result_lines = self.get_exception(f_with_binary_operator)
self.assertEqual(result_lines, expected_error.splitlines())

def test_caret_for_failed_assertion(self):
def f_assert():
test = 3
assert test == 1 and test == 2, "Bug found?"

lineno_f = f_assert.__code__.co_firstlineno
expected_error = (
'Traceback (most recent call last):\n'
f' File "{__file__}", line {self.callable_line}, in get_exception\n'
' callable()\n'
f' File "{__file__}", line {lineno_f+2}, in f_assert\n'
' assert test == 1 and test == 2, "Bug found?"\n'
' ^^^^^^^^^^^^^^^^^^^^^^^\n'
)
result_lines = self.get_exception(f_assert)
self.assertEqual(result_lines, expected_error.splitlines())

def test_traceback_specialization_with_syntax_error(self):
bytecode = compile("1 / 0 / 1 / 2\n", TESTFN, "exec")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix location of the error on a failed assertion.
2 changes: 1 addition & 1 deletion 2 Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -3883,7 +3883,7 @@ compiler_assert(struct compiler *c, stmt_ty s)
VISIT(c, expr, s->v.Assert.msg);
ADDOP_I(c, LOC(s), CALL, 0);
}
ADDOP_I(c, LOC(s), RAISE_VARARGS, 1);
ADDOP_I(c, LOC(s->v.Assert.test), RAISE_VARARGS, 1);

USE_LABEL(c, end);
return SUCCESS;
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.