Repository navigation
fix(pep508): require a comma between version specifiers, and stop inventing one - #22
Merged
Merged
Conversation
…enting one PEP 508 requires a comma between version specifiers. We accepted them written adjacently -- and did not merely accept them. We RE-RENDERED WITH A COMMA THE INPUT NEVER CONTAINED: "urllib3 (>=1.26<2.0)" came back as "urllib3>=1.26,<2.0". Fabricating a constraint boundary out of malformed input is a wrong answer delivered confidently; the publisher's intent is unknowable from that string, and guessing it silently changes which versions resolve. MEASURED over 2,804,135 distinct requirement strings from a production PyPI snapshot (76,741,586 total entries): 756 were accepted with an invented comma. After this change 20 remain, all reaching the same symptom by a different route (see below), and rejections rise by exactly the difference. ROOT CAUSE was the tokenizer's version pattern, not the grammar. The parser loop already required a Comma between clauses, so the leniency was invisible there: the Specifier token's operand was `[^\s,;)]+`, "anything that is not a delimiter", which swallowed "1.5.0>=1.2.0" whole as a single "version". version.NewSpecifiers then re-split that on operators and rendered the comma. The fix follows upstream's structure, which splits the pattern by operator rather than using one permissive operand: "===" is arbitrary equality, whose operand PEP 440 defines as an opaque string that is never interpreted as a version, so it keeps the permissive run; every other operator excludes "<>=~" so two specifiers cannot fuse.⚠️ "!" DELIBERATELY STAYS ADMISSIBLE, because a PEP 440 epoch contains one ("1!2.0"). Excluding it alongside the other operator characters is the obvious next step and it breaks every epoch specifier -- verified by mutation, which is why there is a test for it.⚠️ TWO FURTHER DIVERGENCES WERE FOUND AND ARE DELIBERATELY NOT FIXED HERE. Both predate this change -- each confirmed to behave identically on unmodified main -- and both are documented beside the tests: 1. An uppercase or underscored local label in a SPECIFIER is rejected: "foo ==1.0+UBUNTU_1" errors while upstream accepts it and renders it verbatim. 2. validConstraintRegexp makes the comma between constraints OPTIONAL, and its operator alternation admits an empty operator so a bare version is a valid constraint. Together those let constraints run together: "==0.1dev10.3" parses as "==0.1dev10" plus a bare-version constraint "3" and renders "==0.1dev10,3". That is the same fabricated-comma failure by another route, and it accounts for the 20 remaining cases. The second is the one to be careful with, and the reason it is not in this PR: that regex is shared with NewRSpecifiers, which Package Manager uses for R constraint parsing. Requiring a comma there needs measuring against R data rather than being assumed safe from the Python side.⚠️ ANOTHER OF MY TEST EXPECTATIONS WAS WRONG, found by measuring rather than reading. I asserted "foo ==1.0+ubuntu-1" would render its local label normalized to "ubuntu.1". It does not, and should not: upstream normalizes a bare Version but renders a SPECIFIER's operand verbatim -- SpecifierSet("==1.0+ubuntu-1") is unchanged while Version("1.0+ubuntu-1") becomes "1.0+ubuntu.1". Our behaviour already matched; my expectation did not. Verified by mutation: restoring the old permissive rule fails the adjacency test while leaving the others passing; narrowing "===" too fails the arbitrary-equality test; excluding "!" fails the epoch case. The full suite, including the pypa-ported conformance tables and the rapid property tests, is unchanged and green. CHANGELOG entry goes in 0.2.0's Breaking section rather than Unreleased, since that tag is not cut yet and 0.2.0 is billed as the conformance release. Move it if you would rather cut 0.2.0 as it stands. Refs rstudio/package-manager#19466 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.
Addresses finding F5 of rstudio/package-manager#19466.
What
PEP 508 requires a comma between version specifiers. We accepted them written adjacently — and
did not merely accept them:
Fabricating a constraint boundary out of malformed input is a wrong answer delivered
confidently. The publisher's intent is unknowable from that string, and guessing it silently
changes which versions resolve. Upstream rejects all such inputs.
Measured
Over a production PyPI snapshot: 76,741,586 requirement entries, 2,804,135 distinct
strings.
Rejections rise by exactly the difference. The 20 survivors reach the same symptom by a
different route — see below.
Real examples now rejected:
urllib3 (>=1.26<2.0),boto3 (>=1.23.10<1.24.0),textual>=0.2.1<1,locate (>=1.0==1.*).Root cause was the tokenizer, not the grammar
The parser loop already required a
Commabetween clauses, so the leniency was invisiblethere. The Specifier token's operand was
[^\s,;)]+— "anything that is not a delimiter" —which swallowed
1.5.0>=1.2.0whole as a single "version".version.NewSpecifiersthenre-split it on operators and rendered the comma.
The fix follows upstream's structure, which splits the pattern by operator instead of using
one permissive operand:
===keeps the permissive run, every other operator excludes<>=~.!deliberately stays admissible, because a PEP 440 epoch contains one (1!2.0).Excluding it alongside the other operator characters is the obvious next step and it breaks
every epoch specifier — verified by mutation, which is why there's a test for it.
Both predate this change (each confirmed to behave identically on unmodified
main) and bothare documented beside the tests:
foo ==1.0+UBUNTU_1errors, while upstream accepts it and renders it verbatim.
validConstraintRegexpmakes the comma between constraints optional, and its operatoralternation admits an empty operator so a bare version is a valid constraint. Together those
let constraints run together:
==0.1dev10.3parses as==0.1dev10plus a bare-versionconstraint
3, rendering==0.1dev10,3. Same fabricated-comma failure, different route —and it accounts for the 20 remaining cases.
The second is why it isn't in this PR: that regex is shared with
NewRSpecifiers, whichPackage Manager uses for R constraint parsing. Requiring a comma there needs measuring against R
data rather than being assumed safe from the Python side.
I asserted
foo ==1.0+ubuntu-1would render its local label normalized toubuntu.1. It doesnot, and should not: upstream normalizes a bare
Versionbut renders a specifier's operandverbatim —
SpecifierSet("==1.0+ubuntu-1")is unchanged whileVersion("1.0+ubuntu-1")becomes1.0+ubuntu.1. Our behaviour already matched; my expectation didn't. Found by measuring.Verification
===too!Full suite green, including the pypa-ported conformance tables and the rapid property tests.
-raceclean,gofmtclean,golangci-lint0 issues.Release note
The CHANGELOG entry is in 0.2.0's Breaking section rather than Unreleased, since that tag is
not cut yet and 0.2.0 is billed as the conformance release. Move it if you'd rather cut 0.2.0 as
it stands.