fix: mutate methods of decorated classes - #539
Open
Sanjays2402 wants to merge 1 commit into
Open
Conversation
MutationVisitor._skip_node_and_children skipped any decorated ClassDef and all of its children, so every method of a @DataClass (or any other decorated class) produced zero mutants. A class decorator stays on the original class definition - only methods get trampolines - so the reasons the skip exists (trampoline copying side effects, @Property signatures) do not apply to classes. The skip is now on cst.Decorator itself, which keeps decorator arguments unmutated (e.g. @DataClass(frozen=True) does not become frozen=False) while allowing the class body to be mutated. Closes boxed#480
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.
Closes #480
_skip_node_and_childrenskipped any decoratedClassDeftogether with all its children, so every method of a@dataclassproduced zero mutants. As you noted on the issue, the reasons for skipping decorated functions (trampoline copying side effects,@propertysignatures) don't apply to classes — a class decorator stays on the original class and only the methods get trampolines.Rather than dropping the
ClassDefcheck outright, the skip now applies tocst.Decoratoritself. That keeps decorator arguments unmutated (otherwise@dataclass(frozen=True)mutates tofrozen=False, which is executed at import time) while still recursing into the class body.