-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
Environment
# python -VV
Python 3.11.2 (main, Nov 30 2024, 21:22:50) [GCC 12.2.0]
# uname -a
Linux flower 6.1.0-32-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.129-1 (2025-03-06) x86_64 GNU/Linux
How to reproduce
- Create
main.py
with the following contents:
# main.py
assert 0 <= -1 and 10 < 20
- Run
main.py
. An AssertionError occurs:
mokichi@flower:~/python_bug$ python3 main.py
Traceback (most recent call last):
File "/home/mokichi/python_bug/main.py", line 1, in <module>
assert 0 <= -1 and 10 < 20
^^^^^^^
AssertionError
Problem
Currently, highlighting tells us that the assertion error has occurred in expression 10 < 20
.
However, according to short-circuit evaluation, the expression that has really activated assertion error is the first one: 0 <= -1
.
Possible fixes
-
Highlight only the evaluated part
Evaluate expressions separated byand
from left to right. When an expression gets evaluated to False, highlight only that expression. (I think this is more intuitive since this follows short-circuit evaluation rule.) -
Highlight the whole expression
When any part of assert statement gets evaluated to False, highlight whole expression. This fix may be little unfriendly than previous fix, but better than current incorrect behavior.
CPython versions tested on:
3.11
Operating systems tested on:
Linux
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error