Repository navigation
Conversation
`mutmut apply` replaced the first definition with the mutant's name in its scope. For a function or method with `@overload` stubs that is the first stub, so the mutant was written over it and the implementation was left unchanged. Pick the definition that contains the mutant's source span, which the meta file records since 3.9.0. Without a recorded span, or if no definition contains it, the first definition is used as before. Fixes boxed#665
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.
Fixes #665
mutmut apply(and the apply action inmutmut browse) wrote the mutant of an overloaded function or method over its first@overloadstub instead of the implementation. The implementation further down was left unchanged, so the applied file behaved like the original, and a mutant thatmutmut runreported as killed passed the tests once applied. As @willfrey found in the issue,find_functionreturns the first definition with the mutant's name in its scope, and in an overload group that is the first stub.Following the approach suggested in the issue,
apply_mutantnow passes the mutant's source span tofind_function. The meta file records it insource_span_by_keysince 3.9.0. When the name is defined more than once in the scope,find_functionreturns the definition that contains the span. Without a recorded span (a meta file written before 3.9.0), or if no definition contains it, it returns the first definition, as before.Tests:
test_apply_mutant_to_overloaded_functionapplies a mutant of the issue's example for a top-level function and for a method, with and without the line span index, and checks that only the implementation'sreturnline changed. All 4 cases fail without the fix and pass with it.write_mutants_dirnow records the source spans the waymutmut rundoes.test_apply_mutant_only_changes_the_function_it_belongs_toalso runs without them, so the fallback for older meta files stays covered.tests/mutation: 440 passed, 1 skipped.ruff check,ruff format --checkandmypypass.I also ran the reproducer from the issue end to end (
mutmut run,mutmut apply pkg.mod.x_twice__mutmut_1,pytest). Before the fix, the first stub was replaced andpytestpassed after the apply. With the fix, onlyreturn value * 2becomesreturn value / 2in the implementation andpytestfails (assert 1.0 == 4).