Skip to content

Specifier < that contains prerelease version does not match on valid prerelease versions #788

@notatallshaw

Description

@notatallshaw

This relates to this part of the spec:

The exclusive ordered comparison <V MUST NOT allow a pre-release of the specified version unless the specified version is itself a pre-release. Allowing pre-releases that are earlier than, but not equal to a specific pre-release may be accomplished by using <V.rc1 or similar.

So, for example, <3.0.0a8 is a prerelease specifier, and therefore falls under "unless the specified version is itself a pre-release", I would expect it to then "Allowing pre-releases that are earlier than, but not equal to a specific pre-release", for example 3.0.0a7.

However that does not appear to be the case:

>>> from packaging.specifiers import Specifier
>>> Specifier('<3.0.0a8').contains("3.0.0a7")
False
>>> Specifier('<=3.0.0a8').contains("3.0.0a7")
True

This came up in astral-sh/uv#2646 and I'm aware of the comment #776 (comment), but the spec seems very explicit and even gives an examples that < allows prereleases when the version itself is a prerelease.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions