Skip to content

Comments

SpecifierSet.filter should allow pre-release when no final version matches specifiers, same as Specifier.filter#872

Closed
notatallshaw wants to merge 9 commits intopypa:mainfrom
notatallshaw:specifierset-should-behave-like-specifier-for-pre-releases
Closed

SpecifierSet.filter should allow pre-release when no final version matches specifiers, same as Specifier.filter#872
notatallshaw wants to merge 9 commits intopypa:mainfrom
notatallshaw:specifierset-should-behave-like-specifier-for-pre-releases

Conversation

@notatallshaw
Copy link
Member

@notatallshaw notatallshaw commented Feb 8, 2025

Fixes #856

This brings SpecifierSet in-line with Specifier and the spec. I believe this behavior was incorrectly created from #29, which determined ahead of filtering whether to allow pre-releases or not, but did not introduce a fallback when only pre-releases matched the specifiers.

Interestingly, even though the old behavior is listed in the doc string there were previously no tests for this behavior:

>>> list(SpecifierSet(">=1.2.3").filter(["1.2", "1.5a1"]))
[]

The docstring has been updated and the equivalent tests are added.

@notatallshaw notatallshaw force-pushed the specifierset-should-behave-like-specifier-for-pre-releases branch from 6234741 to 4ed82fd Compare February 8, 2025 22:08
@notatallshaw
Copy link
Member Author

FWIW, I prefer writing a method to return early, and not have large else blocks, but this PR focuses on fixing the bug without refactoring or writing code that conflicts with the existing style.

@notatallshaw notatallshaw force-pushed the specifierset-should-behave-like-specifier-for-pre-releases branch 2 times, most recently from ad6d156 to 7865467 Compare February 13, 2025 13:45
@notatallshaw
Copy link
Member Author

notatallshaw commented Feb 13, 2025

I've updated the tests of both Specifier.filter and SpecifierSet.filter so they match each other, with the exception of the empty string specifier which SpecifierSet accepts but Specifier doesn't.

@notatallshaw notatallshaw force-pushed the specifierset-should-behave-like-specifier-for-pre-releases branch from 6a04147 to 8bc9a3b Compare February 14, 2025 14:11
@notatallshaw
Copy link
Member Author

This is ready for review / merge. FYI the relevant line in the spec is:

accept remotely available pre-releases for version specifiers where there is no final or post release that satisfies the version specifier

Specifier.filter already conforms, but SpecifierSet.filter does not, which means dependency resolution tools like pip that rely on packaging do not correctly follow the spec here.

@notatallshaw
Copy link
Member Author

notatallshaw commented May 2, 2025

I'm pinging just to check this is on someone's queue @brettcannon @pradyunsg @uranusjr as you all approved my last pre-release related PR #794, no rush to review or respond.

I believe that this is a blocker for writing a correct CDCL or CDNL (such as pubgrub) Python packaging resolver that is spec-compliant. This PR is also motivating my work on pypa/pip#13221.

I will be at the Packaging Summit at PyCon US 2025 in a couple of weeks if any questions would better be resolved in real life if any of you are there.

@notatallshaw
Copy link
Member Author

This PR is superseded by #897, if accepted.

@notatallshaw
Copy link
Member Author

To reduce confusion I'm going to close this in favor of #897

If #897 is rejected I'll reopen or recreate this PR.

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.

Why does the filter method of SpecifierSet with a single specifier behave differently to Specifier?

1 participant