fix: annotate -d crashes on a file that is not .py - #2265
Merged
Merged
Conversation
Member
|
This is now released as part of coverage 7.16.0. |
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
coverage annotate -d DIRcrashes with a bareAssertionErrorwhen any measuredfile has an extension other than
.py.A directory with
run.pyand a measuredmod.pyw:The same command without
-dworks, so this is specific to the directory path.Cause
flat_rootnameturns the dot of the extension into an underscore, somod.pywbecomes..._mod_pyw, not..._mod_py.annotate_fileassumesotherwise:
That assert came from
84baf6e1, "refactor: remove an untaken branch inannotate.py", which replaced an
if dest_file.endswith("_py")guard with anassertion. The branch was taken after all, just not by anything in the test
suite: a
.pywfile, or a file measured by a plugin, reaches it.The fix
Put the file's own extension back, whatever it is, instead of assuming
.py.Verification, in plain terms
I added
test_annotate_dir_pyw, which measures a.pywfile and runsannotate -d.Then I put the buggy code back exactly as it reads on
maintoday and re-ranthat test. It failed:
I also tried a subtler wrong fix, hardcoding
".py"instead of reading thefile's real extension. That does not crash, it just writes the wrong filename,
and the test caught that too:
So the test fails both for the original bug and for a near-miss fix, and passes
only with the real one.
tests/test_annotate.pyis 6 passed.ruff checkandruff format --checkareclean, no line over 100 characters.
On the rest of the suite: 194 failures before the change and the same 194 after,
with an empty
diffbetween the two sorted lists. They are pre-existing in thisenvironment, which has no C extension built and no network.
The test runs on Linux: it exercises the reporting path for a
.pywfile, whichis where the crash is, without needing Windows to execute one.
Disclosure: written with AI assistance (Claude Code). I reproduced the crash and the fix by running the real
coverage annotate -dcommand against a measured.pywfile, and ran both checks above and the before/after failure-set comparison myself.