Skip to content

fix: mutate methods of decorated classes - #539

Merged
boxed merged 1 commit into
boxed:mainfrom
Sanjays2402:fix/mutate-decorated-classes
Aug 9, 2026
Merged

boxed merged 1 commit into
boxed:mainfrom
Sanjays2402:fix/mutate-decorated-classes

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

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
@boxed
boxed merged commit dc58270 into boxed:main Aug 9, 2026
5 checks passed
@boxed

boxed commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Thanks!

fmueller added a commit to fmueller/merge-carlo that referenced this pull request Sep 11, 2026
Make the release tasks come last in the v0.1.0 dependency graph:
T-029 publishing now depends on every remaining v0.1.0 task, and the
T-030 release mutation gate depends on T-040 and T-041, which must
precede it.

Defer three tasks to a new, inactive v0.2.0 draft spec so they no
longer gate the first release:

- T-033 dataclass mutation discovery, blocked until a PyPI mutmut
  release contains boxed/mutmut#539. mutmut 3.7.0 skips decorated
  class bodies; discovery evidence is recorded in the task.
- T-020 optional CI enrichment.
- T-036 Taskrail reopening support.

The implementation status and mutation policy docs now state the
deferrals and the resulting gaps, including that v0.1.0 mutation
scores do not cover @DataClass methods.
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

2 participants