Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Generated trampoline names look like public members to tests that inspect classes (more visible since 3.8.0 mutates dataclasses)

Aperta
#586 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@kellyhair ci sta già lavorando.

Dal 26/9/2026.

  • #587 di @kellyhair — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
testing-qa

Direzione di ricerca

Start by reviewing mutmut.utils.format_utils.is_mutated_method_name and the generated names from mutmut.mutation.file_mutation, then inspect the related trampoline handling and README guidance. Compare the proposed filtering approach with the alternative of prefixing generated names, including mutant IDs and classmethod lookup. Done means the chosen behavior covers generated class and module members without breaking existing mutation workflows.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Mutated modules and classes gain functions and dicts whose names don't start with an underscore, such as x_span__mutmut_orig, xǁDateRangeǁ__post_init____mutmut_1 and mutants_x_span__mutmut. Any test that walks vars(), dir() or inspect.getmembers() and treats names without a leading _ as public API sees them as undocumented public members.

This isn't new, but 3.8.0 started mutating @dataclass methods (#480, #539), so it now reaches classes it didn't before. In our project, a test that checks every public member of the exported classes has a docstring started failing in the stats run after upgrading to 3.8.0. The stats pass stopped with exit code 2, so no mutants were tested at all.

Reproduction (mutmut 3.8.0)

import inspect, types
from mutmut.mutation.file_mutation import mutate_file_contents

src = '''
from dataclasses import dataclass

@dataclass
class DateRange:
    """A closed date interval."""
    start: int
    end: int

    def __post_init__(self):
        if self.end < self.start:
            raise ValueError("end before start")

def span(r):
    """Length of the range."""
    return r.end - r.start + 1
'''
mod = types.ModuleType("demo")
exec(compile(mutate_file_contents("demo.py", src).code, "demo.py", "exec"), mod.__dict__)
public = lambda ns: sorted(n for n in ns if not n.startswith("_"))
print(public(vars(mod.DateRange)))
print(public(vars(mod)))

Output:

['xǁDateRangeǁ__post_init____mutmut_1', 'xǁDateRangeǁ__post_init____mutmut_2', 'xǁDateRangeǁ__post_init____mutmut_3', 'xǁDateRangeǁ__post_init____mutmut_4', 'xǁDateRangeǁ__post_init____mutmut_orig']
['DateRange', 'MutantDict', 'dataclass', 'mutants_x_span__mutmut', 'mutants_xǁDateRangeǁ__post_init____mutmut', 'span', 'x_span__mutmut_1', 'x_span__mutmut_2', 'x_span__mutmut_3', 'x_span__mutmut_orig']

The copies of __post_init__ have no docstring. The original is a dunder, so docstring checks usually skip it, but the copies' names aren't dunders.

Options

  1. Prefix generated names with _. This is the real fix, but the mangled names are also the mutant IDs in mutmut show, mutmut apply, the stats and meta files, and is_mutated_method_name. Classmethod dispatch also looks the copies up by name with getattr. It would change every mutant ID, so it's your call whether that's worth it.
  2. Give users a supported way to filter the names. Our workaround copies the logic of mutmut.utils.format_utils.is_mutated_method_name, which isn't public API and doesn't cover the mutants_... dicts. A public predicate plus a README note fixes this without changing any names.

I've opened a PR for option 2. It's small and doesn't break anything, and it doesn't rule out option 1 later.

MutantDict also shows up as a module attribute. It comes from the generated from mutmut.mutation.trampoline import ... MutantDict import. The PR doesn't filter it, because MutantDict is a name user code could also define. Importing it under an alias like _MutantDict would fix that, if you want it.

AI disclosure: Claude Code (Anthropic) did the investigation and wrote this issue and the reproduction, and posted it on my account at my request.

Lingua principale
Python
Stelle
1.5k
Fork
179
Merge medio
1g 18h
PR unite (30g)
6

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di boxed/mutmut

Tutte le issue di boxed/mutmut

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.