Skip to content

feat: add do_not_mutate_patterns config#508

Merged
Otto-AA merged 1 commit into
mainfrom
skipping-regex
May 1, 2026
Merged

feat: add do_not_mutate_patterns config#508
Otto-AA merged 1 commit into
mainfrom
skipping-regex

Conversation

@Otto-AA
Copy link
Copy Markdown
Collaborator

@Otto-AA Otto-AA commented Apr 25, 2026

Fixes #47

This adds following config:

[tool.mutmut]
do_not_mutate_patterns = [
    # disable mutations of all logger.info/debug/... statements
    'logger\.\w+',
    # disable mutating exceptions
    'raise \w+',
]

Mutmut will:

  1. check which lines of the source code match against at least one pattern
  2. skip any expression that starts at any of these lines
def foo():
  logger.info( # <- line matched via pattern; all expressions starting on this line are ignored
    "Hello"
  ) # call expression ends here

  # gets mutated normally
  a = 1

It's important that we only skip expressions and not any AST node. If we would skip all AST nodes, we would also skip the "IndentedBlock" node that starts at the same line as logger.info and spans the whole function body. I think targeting expressions should cover all use cases without unexpected side effects.

This does not support multiline regexes (I did not see a use case for this, could likely be added).

@Otto-AA Otto-AA merged commit b24a12b into main May 1, 2026
10 checks passed
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.

More powerful whitelisting system

1 participant