Skip to content

Scope VersionRange filter of pre-releases to a region so it complies with set algebra#1304

Closed
notatallshaw wants to merge 2 commits into
pypa:mainfrom
notatallshaw:experiment-prerelease-range
Closed

Scope VersionRange filter of pre-releases to a region so it complies with set algebra#1304
notatallshaw wants to merge 2 commits into
pypa:mainfrom
notatallshaw:experiment-prerelease-range

Conversation

@notatallshaw

@notatallshaw notatallshaw commented Jun 28, 2026

Copy link
Copy Markdown
Member

When I designed VersionRange I modeled pre-releases the same way they work in SpecifierSets, but this leads to edge cases under different set operations that don't work correctly (e.g. the example in #1298).

This got me thinking that we could model the pre-release opt-in behavior as a range, instead of True/False/None, so that pre-releases stay consistent under set algebra.

In particular this now makes a & ~b = a - b even for the pre-release policy, not just for the version set they represent.

This does not impact SpecifierSet operations, which can only take the intersection of specifiers.

A simple example is >=1.0 and >=2.0b1 over the versions 1.0, 1.5b1, 2.0b1, 2.5. Individually, >=1.0 filters to 1.0, 2.5 and >=2.0b1 filters to 2.0b1, 2.5. Prior to this change the union of the two would filter the whole list to 1.0, 1.5b1, 2.0b1, 2.5; now it filters to 1.0, 2.0b1, 2.5, as 1.5b1 was never opted in by >=1.0.

This makes VersionRange comply with many more set algebra rules without needing a caveat about pre-release policy.

@notatallshaw notatallshaw force-pushed the experiment-prerelease-range branch from 300baa7 to 222750c Compare June 28, 2026 19:57
@notatallshaw notatallshaw marked this pull request as draft June 30, 2026 01:46
A complement is an exclusion and grants no opt-in, so a & ~b no longer
admits a pre-release that only the excluded b named. complement drops the
region; difference keeps only the minuend's. Involution holds on the
version set, not the opt-in region.
@notatallshaw

Copy link
Copy Markdown
Member Author

This still ends up leaking pre-releases in unexpected places. I have another idea but I'm going to work on it for a bit.

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.

1 participant