Open
Conversation
Otto-AA
reviewed
Mar 7, 2026
| mutants = mutants_for_source("a if b or c else d") | ||
|
|
||
| assert "a if (b or c) and False else d" in mutants | ||
| assert "a if (b or c) or True else d" in mutants |
Collaborator
There was a problem hiding this comment.
Thank you for the PR!
It's an interesting question, but If I'm not mistaken, I don't think the precedence matters in these cases.
For both 1 if (b or c) and False else 2 and 1 if b or (c and False) else 2:
- we always evaluate expression b first
- if b is falsy, we always evaluate c
- we always return False
In the general case, I think adding and False or or True won't effect which expressions we evaluate, regardless of precedence.
Are you aware of a case where it could matter? Then it would be nice to add it here as test case. Otherwise, I think we could simplify the operator_if_exp mutation to directly use node.test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #196
This adds mutations for ternary expressions (
a if cond else b), as discussed in the issue.The new mutations target the
IfExpcondition and force each branch explicitly:can now mutate to:
Implementation notes:
IfExpmutation operator innode_mutation.pyIfExpnode, following the implementation pointer in the issue commentsb or cbefore appendingand False/or True, so we preserve the original condition semanticsI kept this scoped to ternary operators only, not normal
ifstatements, which matches the issue rationale that branch coverage is less helpful for inline conditionals.Tests: