Skip to content

Fix mutmut apply writing a mutant into a same-named function or method - #625

Open
aliassar wants to merge 1 commit into
boxed:mainfrom
aliassar:fix-apply-same-name-624
Open

aliassar wants to merge 1 commit into
boxed:mainfrom
aliassar:fix-apply-same-name-624

Conversation

@aliassar

@aliassar aliassar commented Nov 3, 2026

Copy link
Copy Markdown

mutmut apply looked up the function to replace by its bare name and took the first top-level function or method with that name, so applying a mutant of a top-level size could overwrite Box.size when the class came first in the module. The class name is already in the mutant key, so apply_mutant now passes it to a new find_function helper that searches that class's methods, or only top-level functions when the key has no class. It's a separate helper because read_original_function and read_mutant_function look up the generated names, which already include the class, so mutmut show and the browse diff were never affected. It follows the snippet Ivan Balashov suggested in the issue, thanks for the clear report. The new test applies a mutant of a top-level function and of the methods of two classes that share the name size, with and without the line span index, and checks that only the right function changes. I also ran mutmut run, mutmut apply and mutmut show on the repro from the issue for both mutant keys.

Fixes #624

`apply_mutant` looked the target up by its bare name and took the first
top-level function or method with that name, so a mutant of a top-level
`size` could overwrite `Box.size`. Look it up by the class name in the mutant
key instead, using a separate helper because `read_original_function` relies
on the old lookup.

Based on the fix suggested in boxed#624 by Ivan Balashov.

Fixes boxed#624

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mutmut apply writes a mutant into the wrong function when a method and a function share a name

1 participant