Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion src/poetry/core/constraints/generic/union_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,11 @@ def union(self, other: BaseConstraint) -> BaseConstraint:

else:
assert isinstance(other, MultiConstraint)
# (A or B) or (C and D) => nothing to do
# (A or B) or (A and D) => A or B
if any(c in other.constraints for c in self._constraints):
return self

# (A or B) or (C and D) => nothing to do
new_constraints = [*self._constraints, other]

if len(new_constraints) == 1:
Expand Down
5 changes: 5 additions & 0 deletions tests/constraints/generic/test_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,11 @@ def test_union(
),
),
),
(
UnionConstraint(ExtraConstraint("extra1"), ExtraConstraint("extra2")),
ExtraMultiConstraint(ExtraConstraint("extra1"), ExtraConstraint("extra3")),
UnionConstraint(ExtraConstraint("extra1"), ExtraConstraint("extra2")),
),
],
)
def test_union_extra(
Expand Down
10 changes: 10 additions & 0 deletions tests/version/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,16 @@ def test_single_marker_union_with_inverse() -> None:
'extra == "a" or extra == "c"',
'extra != "a" and extra != "b" or extra == "a" or extra == "c"',
),
(
'extra == "a" or extra == "b"',
'extra == "a" and extra == "c"',
'extra == "a" or extra == "b"',
),
(
'extra == "a" and extra == "c"',
'extra == "a" or extra == "b"',
'extra == "a" or extra == "b"',
),
],
)
def test_single_marker_union_extras(marker1: str, marker2: str, expected: str) -> None:
Expand Down