Skip to content

util/semver: exclude implicit PyPI prereleases from upper-bound constraints - #429

Open
jsibitoye wants to merge 1 commit into
google:mainfrom
jsibitoye:fix/pypi-upper-bound-prereleases-419
Open

jsibitoye wants to merge 1 commit into
google:mainfrom
jsibitoye:fix/pypi-upper-bound-prereleases-419

Conversation

@jsibitoye

Copy link
Copy Markdown

Fixes #419. Thanks to @trackoor and the UCSB PLSE research group for the report and reproduction.

PyPI constraints such as <2.0 use an internal lower bound of 0.dev0. The matcher currently treats that synthetic bound as an explicit request for prereleases, so ordinary upper bounds can admit versions such as 2.0.0.dev4 or 1.5rc1.

This distinguishes the implicit minimum from a lower bound written by the caller. Explicit development/prerelease bounds keep their existing behavior, including >=0dev0 in either conjunction order. Generous matching used for vulnerability ranges remains unchanged. Set operations preserve the distinction without preventing stable-bound unions from merging.

The internal provenance follows the existing treatment of the synthetic SemVer minimum. Textual set notation still cannot distinguish an omitted minimum from an explicit 0.dev0. After Set.String() / ParseSetConstraint() roundtripping, the displayed 0.dev0 is interpreted as an explicit bound and can admit prereleases again. The same provenance limitation exists for the synthetic SemVer minimum; this patch does not change the set format.

Tests cover upper-only constraints, prerelease/development variants, epochs, stable and post releases, explicit zero-development bounds, generous matching, and union/intersection behavior. Nine direct prerelease regression cases and a closed-bound union case fail on the original source and pass with the fix. All five util-module suites and seven Go example builds passed locally with Go 1.27.4, along with semver race tests and go vet.

AI assistance was used for analysis, implementation, and tests.

Avoid treating a synthesized 0.dev0 lower bound as a prerelease opt-in.
Preserve explicit bounds and prerelease admission during set operations.
Keep generous advisory matching unchanged and cover union edge cases.

Fixes google#419.
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.

util/semver: PyPI < and <= constraints without a lower bound match pre-release and .dev versions

1 participant