Skip to content

fix(version): an empty specifier set admits every version, per PEP 508 - #21

Merged
jonyoder merged 1 commit into
mainfrom
empty-specifiers-admit-all
Aug 5, 2026
Merged

jonyoder merged 1 commit into
mainfrom
empty-specifiers-admit-all

Conversation

@jonyoder

@jonyoder jonyoder commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Closes the root cause behind posit-dev/go-pyresolver#8.

What

Specifiers.Check now returns true for a specifier set holding no specifiers. It
previously returned false for 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/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

We 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

specifier.go:310 — andCheck returns true for an empty AND-group, because a conjunction
over no constraints is vacuously true.

specifier.go:274 — Check returned false for zero OR-groups, which is the same statement
one 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 SupportsPython accessor stays, as intention-revealing API
and as protection if it is ever built against an older version of this library.

⚠️ It is a fail-open change, so the blast radius was measured

No input string can reach the changed branch. Every degenerate input either errors or
yields at least one group — verified across "", " ", "\t", ",", ",,", "()",
"( )", "|", "||", "-" and "*", through both NewSpecifiers and the
NewRSpecifiers path PPM uses for R. ("*" 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 rather than silently invalidated.

PPM is unaffected, verified: it pins v0.1.1, and it never calls Check on a
possibly-empty value — src/requirements/filter.go:150-151 guards c.specs == "" and returns
true first, and src/util/version.go:413-416 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 each have to implement themselves.

Tests pin three wrong implementations

Each verified to fail on its own:

Wrong implementation Caught by
dropping the guard (the original defect) TestEmptySpecifiersAdmitEveryVersion, TestEmptySpecifiersAgreeWithAndCheck
an unconditional return true TestNonEmptySpecifiersStillExclude
treating the empty set as a >=0.0.0 floor TestEmptySpecifiersAreNotAFloorOfZero

The 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.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 correction worth recording

While writing this 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 — 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, gofmt clean, golangci-lint 0 issues.

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
jonyoder merged commit 21f393e into main Aug 5, 2026
2 checks passed
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>
@jonyoder
jonyoder deleted the empty-specifiers-admit-all branch August 27, 2026 14:37
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.

1 participant