Skip to content

Idea: Discard candidates that do not match a requirement's extras #11913

Closed
@notatallshaw

Description

@notatallshaw

What's the problem this feature will solve?

Currently when a requirement has an extra but a candidate contains no such extra a warning is printed: https://github.com/pypa/pip/blob/23.0.1/src/pip/_internal/resolution/resolvelib/candidates.py#L498

This scenario could happen either because:

  1. The package extra is incorrectly specified
  2. Or, when backtracking the package extra is provided for some versions of the package and not others

Both of these situations are likely not desirable, for example if an extra is chosen but backtracking goes back to the point where that extra doesn't exist likely this is not a desired version of the package.

In general by having these extras be optional there is an ambiguity in the requirements meaning a user can't be sure whether they are getting foo[bar] or just foo.

Describe the solution you'd like

Discard candidates that do not include the extra, reducing the size of the space needed to search to find a solution when backtracking.

Alternative Solutions

  • Do nothing
  • Throw exception on finding an invalid extra, forcing the user to give more specific requirements
  • Add a flag on to requirements that could be used to "unprefer" requirements that don't match the extra, so at an extra is more likely to be found

Additional context

This warning came up in many cases where I purposefully tried to create obtuse requirements that would take a long time to resolve as part of testing #11908.

Also this would be slightly backwards incompatible in terms of resolution, I suspect if accepted it would need to be introduced behind a feature flag.

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions