Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,24 @@ def of(cls, *markers: BaseMarker) -> BaseMarker:

intersected = False
for i, mark in enumerate(new_markers):
# If we have a MarkerUnion then we can look for the simplifications
# implemented in intersect_simplify().
intersection: BaseMarker | None = None
is_one_union = False
if isinstance(mark, MarkerUnion):
is_one_union = True
intersection = mark.intersect_simplify(marker)
elif isinstance(marker, MarkerUnion):
is_one_union = True
intersection = marker.intersect_simplify(mark)
if intersection is not None:
new_markers[i] = intersection
intersected = True
break

# If we have a SingleMarker then with any luck after intersection
# it'll become another SingleMarker.
if isinstance(mark, SingleMarkerLike):
if not is_one_union and isinstance(mark, SingleMarkerLike):
new_marker = mark.intersect(marker)
if new_marker.is_empty():
return EmptyMarker()
Expand All @@ -671,15 +686,6 @@ def of(cls, *markers: BaseMarker) -> BaseMarker:
intersected = True
break

# If we have a MarkerUnion then we can look for the simplifications
# implemented in intersect_simplify().
elif isinstance(mark, MarkerUnion):
intersection = mark.intersect_simplify(marker)
if intersection is not None:
new_markers[i] = intersection
intersected = True
break

if intersected:
# flatten again because intersect_simplify may return a multi
new_markers = _flatten_markers(new_markers, MultiMarker)
Expand Down Expand Up @@ -833,9 +839,24 @@ def of(cls, *markers: BaseMarker) -> BaseMarker:

included = False
for i, mark in enumerate(new_markers):
# If we have a MultiMarker then we can look for the simplifications
# implemented in union_simplify().
union_: BaseMarker | None = None
is_one_multi = False
if isinstance(mark, MultiMarker):
is_one_multi = True
union_ = mark.union_simplify(marker)
elif isinstance(marker, MultiMarker):
is_one_multi = True
union_ = marker.union_simplify(mark)
if union_ is not None:
new_markers[i] = union_
included = True
break

# If we have a SingleMarker then with any luck after union it'll
# become another SingleMarker.
if isinstance(mark, SingleMarkerLike):
if not is_one_multi and isinstance(mark, SingleMarkerLike):
new_marker = mark.union(marker)
if new_marker.is_any():
return AnyMarker()
Expand All @@ -845,15 +866,6 @@ def of(cls, *markers: BaseMarker) -> BaseMarker:
included = True
break

# If we have a MultiMarker then we can look for the simplifications
# implemented in union_simplify().
elif isinstance(mark, MultiMarker):
union = mark.union_simplify(marker)
if union is not None:
new_markers[i] = union
included = True
break

if included:
# flatten again because union_simplify may return a union
new_markers = _flatten_markers(new_markers, MarkerUnion)
Expand Down