Repository navigation
fix(version): an empty specifier set admits every version, per PEP 508 - #21
Merged
Merged
Conversation
PEP 508 makes a requirement's version specifier optional, and a requirement
without one accepts any version. The canonical spelling of that is an empty
specifier set, which is what upstream produces and what upstream treats as
containing everything -- measured against pypa/packaging 26.2:
Requirement('flask').specifier -> <SpecifierSet('')> len 0
contains '3.0.0' -> True
contains '0.1' -> True
contains '99!1.0' -> True
contains '2.0.0rc1' -> True
Specifiers.Check answered false to all of those. "No constraint" was being read
as "no versions" instead of "all versions", which inverts every gate built on a
specifier set: a caller filtering candidates against an unconstrained set
discards all of them and concludes the package is unsatisfiable rather than
unconstrained.
THE PACKAGE WAS ALREADY INCONSISTENT WITH ITSELF, which is what makes this a
defect rather than a debatable choice. andCheck returns true for an empty
AND-group, because a conjunction over no constraints is vacuously true. Zero
OR-groups is the same statement one level up, and the two disagreed.
This is the root cause of the inversion fixed downstream in
posit-dev/go-pyresolver#8, where an absent Requires-Python -- 2,027,153 versions
in a production PyPI snapshot -- was read as "compatible with no interpreter at
all." That module's accessor stays as intention-revealing API and as protection
if it is ever built against an older version of this one.
⚠️ THIS IS A FAIL-OPEN CHANGE, so the blast radius was measured rather than
argued. NO INPUT STRING CAN REACH IT: every degenerate input either errors or
yields at least one group, verified across "", " ", "\t", ",", ",,", "()",
"( )", "|", "||", "-" and "*" through both NewSpecifiers and NewRSpecifiers
("*" yields one group, >=0.0.0). The only route to a zero-group Specifiers is
Go's zero value, which today gets the wrong answer anyway. That reachability
fact is now a test, so if a future change makes some input parse to zero groups
the risk assessment gets redone instead of silently invalidated.
Also verified: PPM is unaffected. It pins v0.1.1, and it never calls Check on a
possibly-empty value -- src/requirements/filter.go guards specs == "" and returns
true first, and PythonCheckSpecifier returns early on a parse error. That
workaround existing in the only other consumer is itself evidence that this is
the semantics callers expect and currently have to implement themselves.
TESTS PIN THREE WRONG IMPLEMENTATIONS, each verified to fail on its own:
- dropping the guard (the original defect);
- an unconditional `return true`, which would be a far worse bug than the one
being fixed, caught by asserting a real constraint still EXCLUDES;
- treating the empty set as a ">=0.0.0" floor. That one is subtler than it
looks and my first draft of these tests missed it: a dev or pre-release
segment sorts BELOW the release it belongs to, so 0.0.0.dev0 and 0.0.0a1 are
less than 0.0.0 and a >=0.0.0 floor wrongly excludes them. Upstream admits
both under an empty set and rejects both under >=0.0.0.
One thing I got wrong while writing this and corrected: I assumed a ">=0.0.0"
floor would also wrongly exclude pre-releases generally. It does not. Upstream's
contains() admits 2.0.0rc1 under ">=1.0"; PEP 440's default pre-release exclusion
is applied by filter(), not by contains(). Conflating those two is a different
bug, and the test comment now says so explicitly so the distinction is not lost.
CHANGELOG goes in the unreleased 0.2.0 Breaking section, placed first in that
list so it does not textually collide with the entry in #20.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
jonyoder
added a commit
that referenced
this pull request
Aug 7, 2026
…23) v0.2.0 WAS ALREADY CUT. It was tagged and pushed on 2026-08-03 at 3dfc5dc, and proxy.golang.org has served it since: {"Version":"v0.2.0","Time":"2026-08-03T16:19:37Z", "Origin":{"Hash":"3dfc5dc4447367996e677fbf7f7008fa307624d1",...}} Four commits landed after that tag -- #19, #20, #21, #22 -- and three of them wrote their entries into the dated `## [0.2.0]` section rather than `[Unreleased]`, on the stated reasoning that the tag had not been cut yet. So the changelog claimed for v0.2.0 three changes that v0.2.0 does not contain: the required comma between specifiers, the empty-specifier-set inversion, and all-digit local segment normalization. `[Unreleased]` was empty. A GO MODULE TAG IS IMMUTABLE once the proxy has seen it, so there is no version of this that ends with v0.2.0 being correct. The entries move forward instead. Two of the three narrow what parses and one changes rendered output, so per this module's own stated policy -- breaking changes take a minor bump while major is 0 -- the next tag is 0.3.0, not 0.2.1. VERIFIED that the 0.2.0 section is now byte-identical to what the tag shipped: `git diff 3dfc5dc -- CHANGELOG.md` removes exactly one line, the [Unreleased] compare link, which is replaced. Everything else is additive. Also documents #19 under 0.3.0's Notes. It was NOTICE-only so it had no entry, but it is the release's most consequential change for a redistributor: it credits pkginfo and twine, whose material distribution/ ports uncredited through v0.2.0, corrects pypa/packaging's license to the Apache-2.0-OR-BSD-2-Clause dual offer, and deletes a claim that no source from the cited projects was incorporated -- false since tags/ landed on 2026-07-08, and therefore false in v0.1.0, v0.1.1, v0.1.2 and v0.2.0 alike. And adds the guardrail to CLAUDE.md, since the existing rule said entries go under [Unreleased] without saying to verify the assumption that a dated section is unreleased. CI does not validate the changelog. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the root cause behind posit-dev/go-pyresolver#8.
What
Specifiers.Checknow returnstruefor a specifier set holding no specifiers. Itpreviously returned
falsefor every version.Why — PEP 508
PEP 508 makes a requirement's version specifier optional, and a requirement without one
accepts any version. The canonical spelling of that is an empty specifier set. Measured
against
pypa/packaging26.2:We answered
falseto all of those. "No constraint" was being read as "no versions" insteadof "all versions", which inverts every gate built on a specifier set: a caller filtering
candidates against an unconstrained set discards all of them, and concludes the package is
unsatisfiable rather than unconstrained.
The package was already inconsistent with itself
specifier.go:310—andCheckreturnstruefor an empty AND-group, because a conjunctionover no constraints is vacuously true.
specifier.go:274—Checkreturnedfalsefor zero OR-groups, which is the same statementone level up.
That is what makes this a defect rather than a debatable design choice.
This is the root cause of a shipped bug
posit-dev/go-pyresolver#8 fixed the downstream symptom: an absent
Requires-Python—2,027,153 versions in a production PyPI snapshot — was read as "compatible with no
interpreter at all". That module's
SupportsPythonaccessor stays, as intention-revealing APIand as protection if it is ever built against an older version of this library.
No input string can reach the changed branch. Every degenerate input either errors or
yields at least one group — verified across
""," ","\t",",",",,","()","( )","|","||","-"and"*", through bothNewSpecifiersand theNewRSpecifierspath PPM uses for R. ("*"yields one group,>=0.0.0.)The only route to a zero-group
Specifiersis Go's zero value, which today gets the wronganswer anyway. That reachability fact is now a test, so if a future change makes some input
parse to zero groups, the risk assessment gets redone rather than silently invalidated.
PPM is unaffected, verified: it pins
v0.1.1, and it never callsCheckon apossibly-empty value —
src/requirements/filter.go:150-151guardsc.specs == ""and returnstruefirst, andsrc/util/version.go:413-416returns early on a parse error. That workaroundexisting in the only other consumer is itself evidence that this is the semantics callers
expect and currently each have to implement themselves.
Tests pin three wrong implementations
Each verified to fail on its own:
TestEmptySpecifiersAdmitEveryVersion,TestEmptySpecifiersAgreeWithAndCheckreturn trueTestNonEmptySpecifiersStillExclude>=0.0.0floorTestEmptySpecifiersAreNotAFloorOfZeroThe third is subtler than it looks, and my first draft of these tests missed it: a dev or
pre-release segment sorts below the release it belongs to, so
0.0.0.dev0and0.0.0a1areless than
0.0.0, and a>=0.0.0floor wrongly excludes them. Upstream admits both under anempty set and rejects both under
>=0.0.0.One correction worth recording
While writing this I assumed a
>=0.0.0floor would also wrongly exclude pre-releasesgenerally. It does not. Upstream's
contains()admits2.0.0rc1under>=1.0; PEP 440'sdefault pre-release exclusion is applied by
filter(), not bycontains(). Conflating thosetwo is a different bug, and the test comment now says so explicitly so the distinction is not
lost — it is also directly relevant to the separate pre-release selection finding in the
resolver.
Release
CHANGELOG entry goes in the unreleased 0.2.0 Breaking section, placed first in that list so
it does not textually collide with the entry in #20.
go test -race ./...green,gofmtclean,golangci-lint0 issues.