Skip to content

Commit 105ab96

Browse files
committed
Ban negative extras
Negative extras (`extra !=`) are currently technically allowed in the grammar, but they behave strangely: `extra !=` means that package could transitively remove a package from selection through activating an extra. This turns incremental resolution into a global problem: We can't exit a resolution with a conflict when we've exhausted all versions in range including backtracking, we also have to exhaustively search for any package version that may activate the extra which deactivates the `extra !=` requirement which is part of the conflict. This would be fatal to resolver complexity and performance, preventing most of the short-circuiting that makes resolving tractable. Much weirder, with negative extras, adding a new dependency can make a previously impossible resolution solvable: ``` [project] name = "foo" version = "0.1.0" dependencies = [ "numpy >2", "numpy <2; extra != 'old-science'", ] ``` Only by adding a package with `Requires-Dist: foo[old-science]`, this resolves. Using PEP 621, users only get positive extras: `project.optional-dependencies.foo` gets translated into a conjunction of `extra == "foo"` with each requirement's marker. While this may look like a breaking change, it only clarifies the current state of support in tools. From [pip not supporting it](pypa/pip#14139) and [uv not supporting it](astral-sh/uv#20107), we know it is not currently used and safe to remove. This solves the [confusion for users who want to use negative extras for conflicting packages](astral-sh/uv#20107).
1 parent e0c56aa commit 105ab96

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

‎source/specifications/dependency-specifiers.rst‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,8 @@ DO NOT need to define these fields.
457457

458458
The ``extra`` field is also special, as it expects set-like behaviour, but
459459
predates the addition of ``Set of strings`` as a defined marker field type.
460-
Accordingly, ``extra == "name"`` in a dependency declaration is similar to
461-
``"name" in extras``, while ``extra != "name"`` is similar to
462-
``"name" not in extras``. For dependency marker evaluations, the set of extra
460+
It only supports one operation, ``extra == "name"``, which is similar to
461+
``"name" in extras``. For dependency marker evaluations, the set of extra
463462
names used for these comparisons is the full set of requested extras for *that
464463
particular package*, whether requested directly in a top level dependency
465464
declaration, or indirectly in a transitive dependency declaration. Other

0 commit comments

Comments
 (0)