Skip to content
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

Wrong error location in traceback inside an assert #116034

Closed
solanav opened this issue Feb 28, 2024 · 9 comments
Closed

Wrong error location in traceback inside an assert #116034

solanav opened this issue Feb 28, 2024 · 9 comments
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@solanav
Copy link

solanav commented Feb 28, 2024

Bug report

Bug description:

The location in the traceback for this failed assertion:

test = 3
assert test == 1 and test == 2, "Bug found?"

Seems to be wrong. It should show test == 1 as the source of the error:

Traceback (most recent call last):
  File "/home/.../test.py", line 3, in <module>
    assert test == 1 and test == 2, "Bug found?"
                         ^^^^^^^^^
AssertionError: Bug found?

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Linked PRs

@solanav solanav added the type-bug An unexpected behavior, bug, or error label Feb 28, 2024
@Eclips4
Copy link
Member

Eclips4 commented Feb 28, 2024

Hello!
Thanks for the report!
Traceback for current 3.11 branch:

Traceback (most recent call last):
  File "/Users/admin/Projects/cpython/example.py", line 2, in <module>
    assert test == 1 and test == 2, "Bug found?"
                         ^^^^^^^^^
AssertionError: Bug found?

Traceback for current 3.12 branch:

Traceback (most recent call last):
  File "/Users/admin/Projects/cpython/example.py", line 2, in <module>
    assert test == 1 and test == 2, "Bug found?"
AssertionError: Bug found?

Traceback for current main branch:

Traceback (most recent call last):
  File "/Users/admin/Projects/cpython/example.py", line 2, in <module>
    assert test == 1 and test == 2, "Bug found?"
           ^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Bug found?

cc @pablogsal

@pablogsal
Copy link
Member

Error locations are set by the compiler so this is likely a compiler bug. CC @iritkatriel

@iritkatriel
Copy link
Member

iritkatriel commented Feb 28, 2024

in 3.13 it does this:

>>> assert test == 1 and test == 2, "Bug found?"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    assert test == 1 and test == 2, "Bug found?"
           ^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Bug found?

@pablogsal
Copy link
Member

Shouldn't this be just one or the other?

@iritkatriel
Copy link
Member

Shouldn't this be just one or the other?

Since the line numbers are calculated statically, that would require emitting a different RAISE instruction for each clause. Currently we don't.

@iritkatriel iritkatriel self-assigned this Feb 28, 2024
@pablogsal
Copy link
Member

Then it seems there isn't much we can do for 3.13, no? For 3.12 it seems that we don't emit line info

@iritkatriel
Copy link
Member

For 3.13 we could emit more instructions per assert, if we decide the tradeoff is worth it.

I'm looking at 3.11 / 3.12 and will see if there is an easy fix.

@iritkatriel
Copy link
Member

I fixed 3.11 and 3.12 to behave like 3.13. I will close this issue as the problem it reports it resolved.

I'm not sure narrowing the ranges is worth more code. If it ever comes up as an actual problem, we can revisit.

Thank you @solanav .

@solanav
Copy link
Author

solanav commented Feb 29, 2024

Thank you all so much!

fnordahl added a commit to fnordahl/ovs that referenced this issue Apr 8, 2024
The vlog - Python3 test makes use of output from Python
Tracebacks in its test assertion.

In Python 3.13 a line with tophat (``^``) markers is added below
Tracebacks from calls to assert [0], which makes the test fail.
This change of behavior is also backported to the Python 3.12 and
3.11 stable branches [1].

Strip lines containing one or more occurence of the ``^``
character from the output before performing the test assertions.

0: python/cpython#105935
1: python/cpython#116034
Reported-at: https://launchpad.net/bugs/2060434
Signed-off-by: Frode Nordahl <fnordahl@ubuntu.com>
ovsrobot pushed a commit to ovsrobot/ovs that referenced this issue Apr 8, 2024
The vlog - Python3 test makes use of output from Python
Tracebacks in its test assertion.

In Python 3.13 a line with tophat (``^``) markers is added below
Tracebacks from calls to assert [0], which makes the test fail.
This change of behavior is also backported to the Python 3.12 and
3.11 stable branches [1].

Strip lines containing one or more occurence of the ``^``
character from the output before performing the test assertions.

0: python/cpython#105935
1: python/cpython#116034
Reported-at: https://launchpad.net/bugs/2060434
Signed-off-by: Frode Nordahl <fnordahl@ubuntu.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
igsilya pushed a commit to igsilya/ovs that referenced this issue Apr 9, 2024
The vlog - Python3 test makes use of output from Python
Tracebacks in its test assertion.

In Python 3.13 a line with tophat (``^``) markers is added below
Tracebacks from calls to assert [0], which makes the test fail.
This change of behavior is also backported to the Python 3.12 and
3.11 stable branches [1].

Strip lines containing one or more occurrence of the ``^``
character from the output before performing the test assertions.

0: python/cpython#105935
1: python/cpython#116034

Reported-at: https://launchpad.net/bugs/2060434
Signed-off-by: Frode Nordahl <fnordahl@ubuntu.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
igsilya pushed a commit to igsilya/ovs that referenced this issue Apr 9, 2024
The vlog - Python3 test makes use of output from Python
Tracebacks in its test assertion.

In Python 3.13 a line with tophat (``^``) markers is added below
Tracebacks from calls to assert [0], which makes the test fail.
This change of behavior is also backported to the Python 3.12 and
3.11 stable branches [1].

Strip lines containing one or more occurrence of the ``^``
character from the output before performing the test assertions.

0: python/cpython#105935
1: python/cpython#116034

Reported-at: https://launchpad.net/bugs/2060434
Signed-off-by: Frode Nordahl <fnordahl@ubuntu.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
igsilya pushed a commit to igsilya/ovs that referenced this issue Apr 9, 2024
The vlog - Python3 test makes use of output from Python
Tracebacks in its test assertion.

In Python 3.13 a line with tophat (``^``) markers is added below
Tracebacks from calls to assert [0], which makes the test fail.
This change of behavior is also backported to the Python 3.12 and
3.11 stable branches [1].

Strip lines containing one or more occurrence of the ``^``
character from the output before performing the test assertions.

0: python/cpython#105935
1: python/cpython#116034

Reported-at: https://launchpad.net/bugs/2060434
Signed-off-by: Frode Nordahl <fnordahl@ubuntu.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
igsilya pushed a commit to igsilya/ovs that referenced this issue Apr 9, 2024
The vlog - Python3 test makes use of output from Python
Tracebacks in its test assertion.

In Python 3.13 a line with tophat (``^``) markers is added below
Tracebacks from calls to assert [0], which makes the test fail.
This change of behavior is also backported to the Python 3.12 and
3.11 stable branches [1].

Strip lines containing one or more occurrence of the ``^``
character from the output before performing the test assertions.

0: python/cpython#105935
1: python/cpython#116034

Reported-at: https://launchpad.net/bugs/2060434
Signed-off-by: Frode Nordahl <fnordahl@ubuntu.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
igsilya pushed a commit to igsilya/ovs that referenced this issue Apr 9, 2024
The vlog - Python3 test makes use of output from Python
Tracebacks in its test assertion.

In Python 3.13 a line with tophat (``^``) markers is added below
Tracebacks from calls to assert [0], which makes the test fail.
This change of behavior is also backported to the Python 3.12 and
3.11 stable branches [1].

Strip lines containing one or more occurrence of the ``^``
character from the output before performing the test assertions.

0: python/cpython#105935
1: python/cpython#116034

Reported-at: https://launchpad.net/bugs/2060434
Signed-off-by: Frode Nordahl <fnordahl@ubuntu.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
igsilya pushed a commit to igsilya/ovs that referenced this issue Apr 9, 2024
The vlog - Python3 test makes use of output from Python
Tracebacks in its test assertion.

In Python 3.13 a line with tophat (``^``) markers is added below
Tracebacks from calls to assert [0], which makes the test fail.
This change of behavior is also backported to the Python 3.12 and
3.11 stable branches [1].

Strip lines containing one or more occurrence of the ``^``
character from the output before performing the test assertions.

0: python/cpython#105935
1: python/cpython#116034

Reported-at: https://launchpad.net/bugs/2060434
Signed-off-by: Frode Nordahl <fnordahl@ubuntu.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants