Repository navigation
Add set relations and difference to VersionRange - #1298
Conversation
|
GPT 5.5: ðĪ AI text below ðĪ The new difference operation mishandles ranges with arbitrary-string or non-version Review comment:
|
Fixed |
henryiii
left a comment
There was a problem hiding this comment.
This seems quite reasonable.
|
I'm confident this is correct. But I'm also going to experiment with representing the pre-release policy itself as a range. I realized at the moment the union of two ranges such as |
Trying to adapt
VersionRangeto my pubgrub-based resolver nab I found two issues:Solved by adding direct helper methods to avoid the footgun of implementing them wrong
a & ~bintroduced an unwanted pre-release policy:adidn't imply pre-releases butbdidThis needs some new method. My proposal is the set operation
differencewherea - bwill take the pre-release policy ofaand discardb's.This could also be solved with something like
with_prerelease(prerelease), a class method that returns a newVersionRangeobject, but this pushes handling of PEP 440 pre-release policy logic up to the user, which is exactly what I'm trying to avoid withVersionRange.Here's a worked example of the problem:
Changing
A & ~B's policy instead of adding-would not work:&and~have their own correct behavior. Intersection must combine two requirements' policies (folding one asfull() & reqkeeps its policy), and complement must stay an involution (~~r == r). Neither knows it is part of a difference, so-is the operation that treatsBas a bare exclusion.