Skip to content

Fix constraint union treating "not in" same as "!="#925

Merged
radoering merged 1 commit intopython-poetry:mainfrom
dimbleby:fix/constraint-not-in-intersect
Mar 7, 2026
Merged

Fix constraint union treating "not in" same as "!="#925
radoering merged 1 commit intopython-poetry:mainfrom
dimbleby:fix/constraint-not-in-intersect

Conversation

@dimbleby
Copy link
Copy Markdown
Contributor

@dimbleby dimbleby commented Mar 5, 2026

Summary by Sourcery

Adjust constraint union logic so that intersections of two 'not in' constraints are no longer treated as unconstrained, and update tests to reflect the corrected behaviour when combining 'not in' constraints.

Bug Fixes:

  • Correct handling of intersecting two 'not in' generic constraints so they no longer collapse to an unconstrained AnyConstraint.

Tests:

  • Update constraint intersection tests to assert that combining two 'not in' constraints yields the appropriate union of those constraints instead of AnyConstraint.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Mar 5, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts generic constraint union logic so that "not in" is no longer treated equivalently to "!=" during intersection/union, and updates tests to assert the correct composed constraint rather than AnyConstraint for dual "not in" cases.

File-Level Changes

Change Details Files
Refine union logic for generic constraints so that "not in" is not collapsed with "!=" when combining operators.
  • Change the operator set comparison in Constraint.union to only treat the {"!="} combination as a special case instead of both {"!="} and {"not in"}.
  • Preserve distinct behavior for "not in" constraints when intersecting/unioning with others, avoiding over-broad AnyConstraint results.
src/poetry/core/constraints/generic/constraint.py
Adjust tests to capture the correct result of intersecting two "not in" constraints.
  • Replace the expectation of AnyConstraint for intersecting two "not in" constraints with a pair of equivalent UnionConstraint representations of the two "not in" constraints.
  • Document via a comment that values like "tegra-rpi" should not satisfy either of the original "not in" constraints, hence the result should not be AnyConstraint.
tests/constraints/generic/test_constraint.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The updated test now asserts a specific tuple ordering of two UnionConstraint instances to accommodate commutativity; consider asserting equality in an order-insensitive way (e.g. comparing sets or using any across permutations) so the test remains robust if the union implementation changes internal ordering.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The updated test now asserts a specific tuple ordering of two `UnionConstraint` instances to accommodate commutativity; consider asserting equality in an order-insensitive way (e.g. comparing sets or using `any` across permutations) so the test remains robust if the union implementation changes internal ordering.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Two "not in" constraints should intersect to a UnionConstraint, not
collapse to AnyConstraint.
@radoering radoering force-pushed the fix/constraint-not-in-intersect branch from 69900bd to cb6bdf8 Compare March 7, 2026 08:27
@radoering radoering enabled auto-merge (squash) March 7, 2026 08:28
@radoering radoering disabled auto-merge March 7, 2026 08:28
@radoering radoering changed the title Fix constraint intersect treating "not in" same as "!=" Fix constraint union treating "not in" same as "!=" Mar 7, 2026
@radoering radoering enabled auto-merge (squash) March 7, 2026 08:29
@radoering radoering merged commit 240a368 into python-poetry:main Mar 7, 2026
19 checks passed
@dimbleby dimbleby deleted the fix/constraint-not-in-intersect branch March 7, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants