From 22795f85bc30c30ab1c14fbbb3619a3e5d72e69a Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 11 Jun 2024 18:44:49 -0700 Subject: [PATCH] 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 ``` --- crates/pep508-rs/src/marker.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/pep508-rs/src/marker.rs b/crates/pep508-rs/src/marker.rs index 8ffa28015..06a166ba0 100644 --- a/crates/pep508-rs/src/marker.rs +++ b/crates/pep508-rs/src/marker.rs @@ -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); + } } } @@ -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); + } } } }