Closed the-13th-letter closed 1 week ago
@LiuYinCarl can you take a look at this? It sounds like the issue you fixed.
@nedbat I just test it with version 7.6.1, but is works fine. Please give me a little more time to find the truth.
@the-13th-letter Can you use 7.6.0 to test it again with same file and same environment.
@the-13th-letter I just test it with python3.12 and find some thing.
It seems like it has existed before version 7.6.0 and is only available on python3.12.
python3.12 have some change in Lib/token.py, I find a method to solve the buy, I will make a PR later
@LiuYinCarl My apologies, I had already tested 7.6.0 and 7.0.0, but forgotten to mention that in the initial report. On the other hand, I had never thought to test it with different Python versions.
python3.12 have some change in Lib/token.py [...]
So it seems. The "what's new?" entry says it has to do with better f-string parsing (PEP 701).
Describe the bug
When a line of code ends on a multiline f-string that contains backslash continuation in the first line, the coverage HTML report inserts a synthetic line containing the backslash continuation's backslash at the same position (i.e. a line with a lot of whitespace, and then a backslash), following that line. This also increases the total line count. All following lines with coverage info are then misaligned, because the annotation gets assigned to the original line numbers, not the shifted ones.
To Reproduce
(Running Python 3.12.4 on Linux, in a fresh venv, using coverage 7.6.1 installed via
pip install 'coverage === 7.6.1'
.)bug.py
Shell commands
Screenshot of the output:
Note the synthetic line 3, the misaligned partial/missing coloration on lines 8 and 9 (belonging to the code on lines 9 and 10), and the completely absent coloring of line 11. Note further that line 5 (6 in the screenshot) does not get its own synthetic line. Note finally that the syntax highlighting does not mark lines 2–8 as a string.
Expected behavior
I would expect the HTML rendering of the code
bug.py
to match the actual code ofbug.py
.Additional context
run --timid
) instead of the C trace function, and also tried the 3.12sysmon
core, but that didn't change anything. Which strengthens my belief that the collected data is fine, just the HTML reporter is not.