Skip to content

Commit

Permalink
Deduplicate during _flatten_markers()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dimbleby committed Dec 11, 2022
1 parent 913c651 commit 16dce60
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,14 @@ def _flatten_markers(

for marker in markers:
if isinstance(marker, flatten_class):
flattened += _flatten_markers(
for marker in _flatten_markers(
marker.markers, # type: ignore[attr-defined]
flatten_class,
)
else:
):
if marker not in flattened:
flattened.append(marker)

elif marker not in flattened:
flattened.append(marker)

return flattened
Expand Down

0 comments on commit 16dce60

Please sign in to comment.