Fix "pragma: no mutate" on match/case headers being silently ignored - #554
Fix "pragma: no mutate" on match/case headers being silently ignored#554mathieu-lacage wants to merge 1 commit into
Conversation
visit_Match incorrectly assumed that Match has the same structure as an if/elif/else statement and the code was missing a visit_MatchCase to handle individual case statements: - fix visit_Match, add visit_MatchCase - add corresponding parser unit tests - add corresponding e2e mutation tests
|
mathieu@Host-001:~/code-oss/mutmut$ uv run pytest tests/e2e/test_cli_version.py .... [ 1%] ============================================================================================================== 389 passed, 4 skipped in 14.11s =============================================================================================================== |
* Honour 'pragma: no mutate block' on else/except/finally arms _visit_compound_header is only reachable from visit_If/For/While/With/ Try/FunctionDef/ClassDef/Match. In libcst, else, except, except* and finally are separate nodes owning their own suite, so a pragma on their header line reached no visitor and was silently dropped -- while elif, which parses as a nested If, worked. try/except* parses as TryStar, so the pragma on its try line was dropped too. README documents the block pragma as working on 'any compound statement -- functions, classes, if/elif/else, loops, context managers, etc.' Match/MatchCase is left alone; #554 is fixing that. * tests: triple-quote the compound-arm pragma sources The parametrized cases were escaped one-line strings while every other test in the file writes its source as a triple-quoted block with real newlines and indentation. Match the surrounding style so the pragma placement is readable at a glance. No behaviour change. --------- Co-authored-by: Dylan Pulver <dylanpulver@users.noreply.github.com>
visit_Match incorrectly assumed that Match has the same structure as an if/elif/else statement and the code was missing a visit_MatchCase to handle individual case statements:
Disclaimer: I generated this fix and the corresponding unit tests with claude Sonnet. I reviewed extensively both the patch and the tests.