Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with mutmut mutation in presence of type hints #302

Open
pablo-snz opened this issue Jan 24, 2024 · 1 comment
Open

Issue with mutmut mutation in presence of type hints #302

pablo-snz opened this issue Jan 24, 2024 · 1 comment

Comments

@pablo-snz
Copy link

Hi! I'm wondering if there's a direct way to exclude type hints within mutmut. For example, in the following code, I'm getting errors because mutmut tries to mutate the "|" operator to its counterpart "&":

@dataclass
class Specification:
    filter: Criteria | None = None  # Mutates to => Criteria & None = None
    order: Order | None = None  # Also happens in all of the cases below
    limit: int | None = None
    offset: int | None = None

Plus it becomes more complex in a scenario like this where I can't just whitelist the entire line:

user: User | None = self.repo.match(Specification(filter=Equals("email", user.email) | Equals("username", user.username)))

On the other hand, if mutmut cannot handle this right now in a straightforward manner, would it be possible for me to contribute to the repository by adding this functionality?

@boxed
Copy link
Owner

boxed commented Jan 24, 2024

Hmm. I guess in general it would be a good idea to ignore type hints totally, except they are used for behavior in stuff like pydantic.

I am very much open to a PR. Not sure what should be done though. The smallest change would be for the operator mutation for or to not trigger if inside an annotation. A big ugly but would fit this case.

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

No branches or pull requests

2 participants