Could we at least modify the spec to get rid of the == must be typed as a version part for everything except platform_release? platform_release is nearly useless if all you can do is == on it, but there’s no use for any of the other “string” typed values to be viewed as versions, it slows down packaging as creating SpecifierSet/Version is expensive, and it actively breaks things like extras, as == requires version comparisons, which breaks extras like v0.
Here’s my do-as-little-as-possible proposal:
- Change the spec to state all string values only support string comparisons. No more “convert to version if possible”.
- Make
platform_releasehave a new type,string | Version, which has the current behavior (just punting the work on fixing this to later, as it’s the hard one) (Note: this is the current behavior of Version, the name just indicates that this might not always be a Version, while the three fields with Version are always supposed to be Versions).
Note that you can’t really use comparisons with platform_release, as there is no short-circuit evaluation requirement in the spec, so this will error on platforms that have a non-version-like platform_release if you use it, even if you protect it by checking the platform first.[1]
Longer term, things that might be useful to improve the situation for platform_release could be:
- Add short-circuit evaluation to the spec
- Make the version operators other than
==and!=throw an error ifplatform_releaseisn’t convertible to a version. This would have to go with the above short-circuiting behavior; it would help reduce silent errors, for example when a “10something” follows a “9something”. - Maybe find some way to make
platform_releasemore usable across platforms (likely a new field that is stripped down in some way to just version-like numbers?)
(PS: to make matters worse, packaging does not follow the spec when it comes to the Python fallback behavior)
The way packaging used to do it (before LooseVersion was removed), and currently (unreleased) does it is comparisons like < always return False if the value is not a valid Version. Changing the spec to match that is also an option. I can expand on this idea later.
Actually this is changing in the next version of packaging due to fixes in how Specifiers work with legacy versions, but it was true until now. ↩︎