Fix VersionRange.intersect broadening for local-version other#949
Merged
Conversation
VersionRange.intersect(Version) has a special case introduced in python-poetry#579 to handle '>=X+local ∩ public_X' by broadening to '[X+local, next_patch(X))', because per PEP 440 a public-version Version constraint '==X' matches all local-tagged variants of X. The broadening must not fire when 'other' is itself a local-tagged version: '==X+local' matches only the literal point X+local, never a sibling local-tagged variant. For an exclusive lower bound '>X+local ∩ ==X+local' the broadening wrongly returned the non-empty range '(X+local, next_patch(X))' instead of EmptyConstraint, which downstream caused Poetry's solver to derive contradictory punctured-range terms and crash in partial_solution.satisfier with a '[BUG] ... is not satisfied' RuntimeError. Skip the broadening when 'other.is_local()'; whether the literal point falls in the range is then decided entirely by the existing 'self.allows(other)' check above. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/constraints/version/test_version_range.py" line_range="738-747" />
<code_context>
assert isinstance(result, EmptyConstraint)
+def test_intersect_with_local_version_other_does_not_broaden_exclusive_min() -> None:
+ """Regression test: ``>0.21.0+cpu,<0.22.0 ∩ ==0.21.0+cpu`` must be
+ empty. Previously returned ``>0.21.0+cpu,<0.21.1`` because the
+ ``>=X+local ∩ public_X`` broadening fired for local ``other`` too.
+ """
+ excluded_point = Version.parse("0.21.0+cpu")
+ upper = Version.parse("0.22.0")
+
+ exclusive = VersionRange(
+ excluded_point, upper, include_min=False, include_max=False
+ )
+ assert isinstance(exclusive.intersect(excluded_point), EmptyConstraint)
+
+ # Inclusive-lower case still returns the literally-equal point.
+ inclusive = VersionRange(
+ excluded_point, upper, include_min=True, include_max=False
+ )
+ assert inclusive.intersect(excluded_point) == excluded_point
+
+ # Original motivating case (``>=X+local ∩ public X``) still broadens.
</code_context>
<issue_to_address>
**suggestion (testing):** Consider also asserting the symmetric intersection direction for local-version exclusivity.
To better protect against regressions, consider also exercising the symmetric calls (where applicable), e.g. `excluded_point.intersect(exclusive)` and `excluded_point.intersect(inclusive)`, if they share the same logic.
If `Version.intersect(VersionRange)` is part of the supported API and expected to mirror `VersionRange.intersect(Version)`, these assertions would verify empty vs. non-empty behavior is consistent regardless of operand order. Otherwise, a brief comment noting that only the current direction is supported would clarify the intent.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
radoering
approved these changes
Jun 8, 2026
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.
VersionRange.intersect(Version) has a special case introduced in #579 to handle '>=X+local ∩ public_X' by broadening to '[X+local, next_patch(X))', because per PEP 440 a public-version Version constraint '==X' matches all local-tagged variants of X.
The broadening must not fire when 'other' is itself a local-tagged version: '==X+local' matches only the literal point X+local, never a sibling local-tagged variant. For an exclusive lower bound '>X+local ∩ ==X+local' the broadening wrongly returned the non-empty range '(X+local, next_patch(X))' instead of EmptyConstraint, which downstream caused Poetry's solver to derive contradictory punctured-range terms and crash in partial_solution.satisfier with a '[BUG] ... is not satisfied' RuntimeError.
Skip the broadening when 'other.is_local()'; whether the literal point falls in the range is then decided entirely by the existing 'self.allows(other)' check above.
Resolves: python-poetry#