Skip to content

Add mutmut.is_mutmut_generated_name for tests that inspect classes - #587

Open
kellyhair wants to merge 1 commit into
boxed:mainfrom
kellyhair:expose-generated-name-helper
Open

kellyhair wants to merge 1 commit into
boxed:mainfrom
kellyhair:expose-generated-name-helper

Conversation

@kellyhair

@kellyhair kellyhair commented Sep 26, 2026 •

Copy link
Copy Markdown

Refs #586.

Mutated code adds functions (x_foo__mutmut_orig, xǁClsǁmethod__mutmut_1) and mutants_... dicts to modules and classes. Their names don't start with _, so tests that walk vars(), dir() or inspect.getmembers() treat them as public members. 3.8.0 started mutating dataclass methods, so this now happens in more codebases, and a failing introspection test in the stats run means no mutants get tested.

This PR doesn't rename anything. It gives users a supported way to filter the generated names:

  • mutmut.is_mutmut_generated_name(name) in mutmut.utils.format_utils, re-exported from mutmut. It matches the same names as is_mutated_method_name plus the mutants_x...__mutmut dicts.
  • A README section, "Tests that inspect modules or classes", with a usage example.
  • Tests that mutate a small file containing a dataclass and check that every generated class member and module attribute is filtered, while length, span, DateRange etc. are kept. There's also a list of lookalike names that must not match.
  • A HISTORY entry under "Unreleased".

Not included, see the issue: renaming the generated names (it would change every mutant ID) and the MutantDict import that shows up at module level.

uv run pytest: 469 passed, 2 skipped. pre-commit run is clean on the changed files.

AI disclosure: Claude Code (Anthropic, Claude Opus 5.5) wrote this PR (code, tests, docs and this description) and opened it on my account at my request.

I (@kellyhair) will read and reply to review comments directly.

Mutated files add functions (x_foo__mutmut_orig, xǁClsǁmethod__mutmut_1)
and mutants_... dicts whose names do not start with an underscore, so
tests that walk vars()/dir()/inspect.getmembers() see them as public
members. Since 3.8.0 mutates @DataClass methods, this shows up in more
codebases. Expose a public predicate for filtering them and document it.

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.

1 participant