Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

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.

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