Skip to content

maint: add pre-commit#473

Open
nicklafleur wants to merge 3 commits intoboxed:mainfrom
lyft:nicklafleur/pre-commit
Open

maint: add pre-commit#473
nicklafleur wants to merge 3 commits intoboxed:mainfrom
lyft:nicklafleur/pre-commit

Conversation

@nicklafleur
Copy link

👋 Hi there mutmut maintainers.

We at Lyft have been tinkering internally with mutmut as a means to integrate some new approaches to testing and test quality evaluation. We've made some pretty considerable refactors to the framework that we would like to start merging to the upstream, but wanted to start with some housekeeping items as a show of good faith and thanks for all your work so far.

A sneak peak of some of the changes we have made so far are (all broken down into manageable commits and PRs of course):

  • Support for Enums, @classmethods, and @staticmethods
  • New pragma annotation support for scoped ignoring of classes and functions
  • Performance optimizations resulting in >95% runtime reductions for incremental testing
  • New run isolation modes to support various libraries that pollute the process state
  • Transitive dependency tracking and UI improvements
  • and more!

Please feel free to reach out to me directly at nicholaslafleur@lyft.com if you would like to discuss.

Copy link
Collaborator

@Otto-AA Otto-AA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work, I'm curious to see what you changed :)

This PR looks fine, and I like that formatting is done in a separate PR for easier reviewing. Some notes:

I think we should exclude e2e_projects and tests/data/test_generation folders, the changes there caused the tests to fail. Some of the code there has "perfect imperfections" (as noted in the comments, we want to test that mutmut can handle code stretching over multiple lines, and stuff like Union). I don't really mind if the code quality there is bad.

The pre-commit version is pretty outdated (~3 years), is there a particular reason for this? If using an up-to-date version would cause merge-conflicts, we can postpone upgrading until you submitted the other PRs.

And small documentation nitpick: I like that formatting is not validated as part of the CI, so we keep it simple for new contributors. However, I think we could add pre-commit to the dev-dependencies (uv add --dev pre-commit ), and mention pre-commit install in the CONTRIBUTING page for motivated users

n = 1 \
+ 2
# should mutate keys and values
d = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess these got removed because they are unused? Would be nice to keep them and also keep the original formatting (which tests how mutmut+coverage.py handles weird multiline statements).

In general, I would tend to exclude the e2e_projects from formatting+linting

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call for sure, will convert back to draft and fix

def some_func_clone(a, b: str = "111", c: Callable[[str], int] | None = None) -> int | None: pass # pragma: no mutate

def some_func_clone(a, b: str = "111", c: Callable[[str], int] | None = None) -> int | None:
pass # pragma: no mutate
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need the # pragma: no mutate on the function definition line (the b: str = "111" gets mutated to b: str = "XX111XX" like this)

import ctypes
from collections.abc import Callable
from functools import cache
from typing import Union
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep old constructs like Union in the E2E tests to ensure we still support them

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh good call yeah I missed this when reviewing the warnings thanks

pyproject.toml Outdated
target-version = "py310"

[tool.ruff.lint]
select = ["E", "F", "W", "B", "C4", "UP"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add following rules, could we remove the black and autoflake pre-commit hooks?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

@nicklafleur nicklafleur marked this pull request as draft February 28, 2026 15:44
@nicklafleur
Copy link
Author

@Otto-AA thanks for the review, I have the complete public set of changes here https://github.com/lyft/mutmut/tree/nicklafleur/oss-complete that you can check out. It's quite substantial (+15k, -3k) but everything is very malleable in my mind and open to debate. We are by no means blocked internally so happy to evolve things in a measured way here.

Working on your suggestions now :)

@nicklafleur nicklafleur force-pushed the nicklafleur/pre-commit branch 2 times, most recently from 30b524d to 90a1798 Compare February 28, 2026 17:04
@nicklafleur nicklafleur force-pushed the nicklafleur/pre-commit branch from 90a1798 to 6bb6a62 Compare February 28, 2026 17:10
@nicklafleur nicklafleur requested a review from Otto-AA February 28, 2026 17:11
@nicklafleur nicklafleur marked this pull request as ready for review February 28, 2026 17:12
@nicklafleur
Copy link
Author

I believe I've addressed all the changes. All the snapshots being changed to segfault codes is due to setproctitle which I have a fix coming for in a future PR. Happy to just reset it to the remote version if you would prefer.

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.

2 participants