Skip to content

fix: mutate methods of decorated classes - #539

Open
Sanjays2402 wants to merge 1 commit into
boxed:mainfrom
Sanjays2402:fix/mutate-decorated-classes
Open

fix: mutate methods of decorated classes#539
Sanjays2402 wants to merge 1 commit into
boxed:mainfrom
Sanjays2402:fix/mutate-decorated-classes

Conversation

@Sanjays2402

Copy link
Copy Markdown

Closes #480

_skip_node_and_children skipped any decorated ClassDef together with all its children, so every method of a @dataclass produced zero mutants. As you noted on the issue, the reasons for skipping decorated functions (trampoline copying side effects, @property signatures) don't apply to classes — a class decorator stays on the original class and only the methods get trampolines.

Rather than dropping the ClassDef check outright, the skip now applies to cst.Decorator itself. That keeps decorator arguments unmutated (otherwise @dataclass(frozen=True) mutates to frozen=False, which is executed at import time) while still recursing into the class body.

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
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.

@dataclass methods produce zero mutants

1 participant