Skip to content

Allow URL constraints to apply to requirements with extras#13886

Merged
pradyunsg merged 1 commit into
pypa:mainfrom
pradyunsg:resolver-constraints-extras
Apr 17, 2026
Merged

Allow URL constraints to apply to requirements with extras#13886
pradyunsg merged 1 commit into
pypa:mainfrom
pradyunsg:resolver-constraints-extras

Conversation

@pradyunsg

@pradyunsg pradyunsg commented Apr 5, 2026

Copy link
Copy Markdown
Member

Fixes #12018
Closes #12025 which it supercedes

I blame @ichard26 for making to me stare at this too long by asking me to review what kinda effort it would take to tackle https://github.com/pypa/pip/milestone/47.


Also, shoutout to @harupy for filing such a clear bug report -- I was able to recreate it even a few years down the line (with newer wheel & Python versions), and that was helped immensely by the fact that your report was clear, concise and to the point. It is appreciated! ^.^

Combining a URL-pinned constraint with a requirement that requests
extras -- e.g. pinning `pandas` to a wheel URL while installing
`pandas[performance]` -- used to crash the resolver with
`AssertionError: 'pandas[performance]' != 'pandas' for wheel`.

Constraints are keyed by base name, and `_get_with_identifier`
intentionally falls back from `pkg[extra]` to `pkg` so that version/hash
constraints don't need to be restated per extras combination. That
fallback works well for specifier/hash data, but a constraint's link
carries identity -- it *is* `pkg`, not `pkg[extra]` -- and flowing it
into `_iter_candidates_from_constraints` under the extras-bearing
identifier falls over because there's no handling of extras in it.

Extracting the extras from the identifier (similar to how
`_iter_explicit_candidates_from_base` already adapts regular
requirements) and wrapping it in an `ExtrasCandidate` corrects the
mismatch, handling the extras & constraints appropriately.
@pradyunsg pradyunsg force-pushed the resolver-constraints-extras branch from 10990d0 to 0656b71 Compare April 5, 2026 22:01
@pradyunsg pradyunsg marked this pull request as ready for review April 5, 2026 22:01
@sbidoul sbidoul added this to the 26.1 milestone Apr 11, 2026

@sbidoul sbidoul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tested it fixes the linked issue. Thanks !

"""
extras: frozenset[str] = frozenset()
base_identifier = identifier
with contextlib.suppress(InvalidRequirement):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe add little comment here explaining the reason for the suppressed exception?

@pradyunsg pradyunsg Apr 17, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've gotten too used to $work approach of treating commit messages as coding artifacts. 😅

As that notes, this is basically mirroring the extraction of extras we do in another spot already (and was a bit messy to extract into common code).

@sbidoul sbidoul modified the milestones: 26.1, Drop the legacy resolver Apr 12, 2026
@sbidoul sbidoul added the C: constraint Dealing with "constraints" (the -c option) label Apr 12, 2026
@pradyunsg pradyunsg enabled auto-merge (squash) April 17, 2026 20:47
@pradyunsg pradyunsg disabled auto-merge April 17, 2026 20:49
@pradyunsg pradyunsg merged commit b97708a into pypa:main Apr 17, 2026
36 checks passed
@pradyunsg pradyunsg deleted the resolver-constraints-extras branch April 17, 2026 20:49
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bot:chronographer:provided C: constraint Dealing with "constraints" (the -c option)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AssertionError when installing a package with an extra and a URL constraint

2 participants