Flatten ORs and ANDs in marker construction (#4260)

## 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
```
This commit is contained in:
Charlie Marsh 2024-06-11 18:44:49 -07:00 committed by GitHub
parent 44041bccd2
commit 22795f85bc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1860,9 +1860,13 @@ impl MarkerTree {
_ => {} _ => {}
} }
if let MarkerTree::And(ref mut exprs) = *self { if let MarkerTree::And(ref mut exprs) = *self {
if let MarkerTree::And(tree) = tree {
exprs.extend(tree);
} else {
exprs.push(tree); exprs.push(tree);
} }
} }
}
/// Combine this marker tree with the one given via a disjunction. /// Combine this marker tree with the one given via a disjunction.
/// ///
@ -1878,9 +1882,13 @@ impl MarkerTree {
_ => {} _ => {}
} }
if let MarkerTree::Or(ref mut exprs) = *self { if let MarkerTree::Or(ref mut exprs) = *self {
if let MarkerTree::Or(tree) = tree {
exprs.extend(tree);
} else {
exprs.push(tree); exprs.push(tree);
} }
} }
}
} }
impl Display for MarkerTree { impl Display for MarkerTree {