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
10 changes: 4 additions & 6 deletions src/poetry/core/constraints/generic/constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,11 @@ def allows_any(self, other: BaseConstraint) -> bool:

return True

elif isinstance(other, MultiConstraint):
return self._operator == "!="
if isinstance(other, MultiConstraint):
return all(self.allows_any(c) for c in other.constraints)

elif isinstance(other, UnionConstraint):
return self._operator == "!=" and any(
self.allows_any(c) for c in other.constraints
)
if isinstance(other, UnionConstraint):
return any(self.allows_any(c) for c in other.constraints)

return other.is_any()

Expand Down
25 changes: 25 additions & 0 deletions tests/constraints/generic/test_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,31 @@ def test_allows(
False,
False,
),
# "in" / "not in" with MultiConstraint and UnionConstraint
(
Constraint("tegra", "in"),
MultiConstraint(Constraint("win32", "!="), Constraint("linux", "!=")),
True, # "1.2-tegra" contains "tegra" and is neither "win32" nor "linux"
False,
),
(
Constraint("tegra", "not in"),
MultiConstraint(Constraint("win32", "!="), Constraint("linux", "!=")),
True, # "darwin" has no "tegra" and is neither "win32" nor "linux"
False,
),
(
Constraint("tegra", "in"),
UnionConstraint(Constraint("1.2-tegra"), Constraint("plain")),
True, # "tegra" is in "1.2-tegra"
False,
),
(
Constraint("tegra", "in"),
UnionConstraint(Constraint("plain"), Constraint("other")),
False, # "tegra" is not in "plain" or "other"
False,
),
],
)
def test_allows_any_and_allows_all(
Expand Down