Skip to content

Commit 5f22121

Browse files
committed
Deduplicate during _flatten_markers()
The potential downside of the approach in this series of commits is that cnf() and dnf() can, in the worst case, be exponentially expensive. eg `cnf((a1 and b1) or (a2 and b2) or ... (an and bn))` generates 2^n intersections. In practice, markers on python packages seem not to get long enough for this to be an issue. Deduplicating the markers on unions and intersections is the lowest of low-hanging fruit in mitigating this.
1 parent 913c651 commit 5f22121

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/poetry/core/version/markers.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,14 @@ def _flatten_markers(
370370

371371
for marker in markers:
372372
if isinstance(marker, flatten_class):
373-
flattened += _flatten_markers(
373+
for _marker in _flatten_markers(
374374
marker.markers, # type: ignore[attr-defined]
375375
flatten_class,
376-
)
377-
else:
376+
):
377+
if _marker not in flattened:
378+
flattened.append(_marker)
379+
380+
elif marker not in flattened:
378381
flattened.append(marker)
379382

380383
return flattened

0 commit comments

Comments
 (0)