diff --git a/src/poetry/core/constraints/generic/constraint.py b/src/poetry/core/constraints/generic/constraint.py index c64a66c6a..fb4f79913 100644 --- a/src/poetry/core/constraints/generic/constraint.py +++ b/src/poetry/core/constraints/generic/constraint.py @@ -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() diff --git a/tests/constraints/generic/test_constraint.py b/tests/constraints/generic/test_constraint.py index 73063781e..ad2629168 100644 --- a/tests/constraints/generic/test_constraint.py +++ b/tests/constraints/generic/test_constraint.py @@ -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(