Skip to content

Commit

Permalink
Flatten ORs and ANDs in marker construction (#4260)
Browse files Browse the repository at this point in the history
## Summary

If we're ORing an OR, we should just append rather than nesting in
another OR.

In my branch, this let us simplify:

```
python_version < '3.10' or python_version > '3.12' or (python_version < '3.8' or python_version > '3.12')
```

To:

```
python_version < '3.10' or python_version > '3.12
```
  • Loading branch information
charliermarsh authored Jun 12, 2024
1 parent 44041bc commit 22795f8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crates/pep508-rs/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1860,7 +1860,11 @@ impl MarkerTree {
_ => {}
}
if let MarkerTree::And(ref mut exprs) = *self {
exprs.push(tree);
if let MarkerTree::And(tree) = tree {
exprs.extend(tree);
} else {
exprs.push(tree);
}
}
}

Expand All @@ -1878,7 +1882,11 @@ impl MarkerTree {
_ => {}
}
if let MarkerTree::Or(ref mut exprs) = *self {
exprs.push(tree);
if let MarkerTree::Or(tree) = tree {
exprs.extend(tree);
} else {
exprs.push(tree);
}
}
}
}
Expand Down

0 comments on commit 22795f8

Please sign in to comment.