fix: correct allows_all containment check for "!=" vs "not in"#955
Open
hexonal wants to merge 2 commits into
Open
fix: correct allows_all containment check for "!=" vs "not in"#955hexonal wants to merge 2 commits into
hexonal wants to merge 2 commits into
Conversation
Constraint.allows_all() compared self.value not in other.value when self is "!=" and other is "not in", but the correct check has the same shape as the existing "not in"/"not in" case: other.value in self.value. For example, "os_name != 'a'" does not allow everything "'b' not in os_name" allows, since os_name == "a" satisfies the latter but not the former; the old formula returned True here, causing the "!=" term to be dropped when combined with "and". Fixes python-poetry/poetry#10977.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes python-poetry/poetry#10977
Constraint.allows_all()had a containment check backwards for the case whereselfis a!=constraint andotheris anot inconstraint. It testedself.value not in other.value, but the correct check has the same shape as the existingnot in/not inbranch just above it:other.value in self.value.Concretely:
This happened because
MultiMarker/constraint intersection logic usesallows_allto drop a clause it believes is redundant. The old formula wrongly consideredos_name != "a"redundant given"b" not in os_name, even thoughos_name == "a"satisfies the latter but not the former.I merged the two branches for
self._operator == "not in"andself._operator == "!="underother.operator == "not in"since they resolve to the identical correct formula.Added regression tests in
tests/constraints/generic/test_constraint.py(directallows_allcases) andtests/version/test_markers.py(the exact marker/validate scenario from the issue, plus two adjacent cases).