Skip to content

Narrow >V post-release exclusion to match spec#1141

Merged
notatallshaw merged 2 commits intopypa:mainfrom
notatallshaw:fix/greater-than-dev-postrelease-exclusion
Apr 5, 2026
Merged

Narrow >V post-release exclusion to match spec#1141
notatallshaw merged 2 commits intopypa:mainfrom
notatallshaw:fix/greater-than-dev-postrelease-exclusion

Conversation

@notatallshaw
Copy link
Copy Markdown
Member

Similar to #1140 (the < counterpart), found while looking at edge cases for #1119 and #1120.

The spec says:

The exclusive ordered comparison >V MUST NOT allow a post-release of the given version unless V itself is a post release.

The current code uses _base_version to check this, which strips pre, post, dev, and local from both sides. This is too broad when V is a pre-release or dev release, because it treats post-releases of the base release as post-releases of V.

For example, >1.0.dev1 accepts 1.0 but rejects 1.0.post0:

>>> Specifier(">1.0.dev1").contains("1.0")
True
>>> Specifier(">1.0.dev1").contains("1.0.post0")
False

1.0.post0 is a post-release of 1.0, not of 1.0.dev1. Since 1.0 itself is accepted, excluding 1.0.post0 is incoherent.

The fix replaces _base_version(prospective) == _base_version(spec) with _post_base(prospective) == spec, which checks whether the prospective version is actually a post-release of the spec version rather than just sharing its release segment.

@notatallshaw
Copy link
Copy Markdown
Member Author

notatallshaw commented Mar 29, 2026

This one feels more intuitive to me than #1140, I am much less concerned about the behavior change it introduces, the fact that currently >1.0.dev matches 1.0 but not 1.0.post0 is surprising and not spec compliant.

notatallshaw added a commit to notatallshaw/packaging that referenced this pull request Apr 2, 2026
325 Hypothesis tests that verify algebraic invariants
from the version specifiers specification. Each test
class quotes the spec paragraph it validates.

Tests are excluded from coverage and run as a separate
CI job via `nox -s property_tests`.

Two tests are expected to fail until pypa#1140 and pypa#1141
are merged (exclusive comparison exclusion rules).
notatallshaw added a commit to notatallshaw/packaging that referenced this pull request Apr 2, 2026
325 Hypothesis tests that verify algebraic invariants
from the version specifiers specification. Each test
class quotes the spec paragraph it validates.

Tests are excluded from coverage and run as a separate
CI job via `nox -s property_tests`.

Two tests are expected to fail until pypa#1140 and pypa#1141
are merged (exclusive comparison exclusion rules).
notatallshaw added a commit to notatallshaw/packaging that referenced this pull request Apr 2, 2026
325 Hypothesis tests that verify algebraic invariants
from the version specifiers specification. Each test
class quotes the spec paragraph it validates.

Tests are excluded from coverage and run as a separate
CI job via `nox -s property_tests`.

Two tests are expected to fail until pypa#1140 and pypa#1141
are merged (exclusive comparison exclusion rules).
notatallshaw added a commit to notatallshaw/packaging that referenced this pull request Apr 2, 2026
325 Hypothesis tests that verify algebraic invariants
from the version specifiers specification. Each test
class quotes the spec paragraph it validates.

Tests are excluded from coverage and run as a separate
CI job via `nox -s property_tests`.

Two tests are expected to fail until pypa#1140 and pypa#1141
are merged (exclusive comparison exclusion rules).
notatallshaw added a commit to notatallshaw/packaging that referenced this pull request Apr 2, 2026
325 Hypothesis tests that verify algebraic invariants
from the version specifiers specification. Each test
class quotes the spec paragraph it validates.

Tests are excluded from coverage and run as a separate
CI job via `nox -s property_tests`.

Two tests are expected to fail until pypa#1140 and pypa#1141
are merged (exclusive comparison exclusion rules).
notatallshaw added a commit to notatallshaw/packaging that referenced this pull request Apr 2, 2026
325 Hypothesis tests that verify algebraic invariants
from the version specifiers specification. Each test
class quotes the spec paragraph it validates.

Tests are excluded from coverage and run as a separate
CI job via `nox -s property_tests`.

Two tests are expected to fail until pypa#1140 and pypa#1141
are merged (exclusive comparison exclusion rules).
@notatallshaw
Copy link
Copy Markdown
Member Author

The tests I'm proposing in #1144 show that this fixes an edge case where the current behavior breaks the monotonic invariant, that given versions v1 and v2 and v2 > v1 then if the specifier >V matches v1 it should also match v2.

@notatallshaw notatallshaw force-pushed the fix/greater-than-dev-postrelease-exclusion branch from f0c6483 to 48d948a Compare April 5, 2026 14:25
@notatallshaw notatallshaw merged commit 04a7600 into pypa:main Apr 5, 2026
56 checks passed
This was referenced Apr 13, 2026
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