Repository navigation
Write tuples, sets, missing, and rationals as YAML values - #273
Merged
quinnj-bot[bot] merged 2 commits intoNov 18, 2026
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The writer printed these with string(), so (1, 2) became the text "(1, 2)" and loaded back as a string, and a tuple holding "a: b" loaded as a mapping. Tuples and sets now go through the sequence writer, missing is written as null like nothing (as a value or a key), and a rational is written as the nearest float. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #273 +/- ##
==========================================
+ Coverage 91.33% 91.36% +0.02%
==========================================
Files 15 15
Lines 1709 1713 +4
==========================================
+ Hits 1561 1565 +4
Misses 148 148 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Nov 18, 2026
Closed
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.
Why
YAML.writeprinted tuples, sets,missing, and rationals as Julia source text, which loads back as a string.YAML.yaml((1, 2))gave(1, 2), which loads as the string"(1, 2)". A tuple holding"a: b"gave(1, "a: b"), which loads as the mappingDict("(1, \"a" => "b\")").missingloaded as the string"missing", and1//3as the string"1//3".What changed
missingis written as null (~), likenothing, both as a value and as a key. It loads back asnothing.1//4loads as0.25, and1//0is written as.inf.The writer recognized sequences only as
AbstractVector, in the vector method and in the two checks that put a nested collection on its own line. ASequenceunion now names the types written as sequences. Both checks use it, and tuples and sets are collected into a vector before the vector writer runs.Why a float for rationals
YAML has no rational type. A float loads as a number in YAML.jl and in every other reader. The two lossless options load as something that is not a number. One is the string
"1//3", which master already produced. The other is a{num: 1, den: 3}mapping, which is what JSON.jl's struct fallback writes. The cost is precision:1//3comes back as0.3333333333333333.rationalizerecovers small ratios.Scope
string(key).Conflict with #264
#264 widens the same two checks to
AbstractArray. Whichever PR merges second needs a two-line conflict resolution. KeepSequencein both checks, and change the definition toconst Sequence = Union{AbstractArray,Tuple,AbstractSet}. Keep the vector method onAbstractVector, so #264'sAbstractArraymethod still handles matrices. I checked that resolution locally: #264'sissue #135testset and this PR's testset both pass, andDict("t" => ([1 2; 3 4], Set([1])))round-trips.Verification
Pkg.test()passes on Julia 1.12.6 and on Julia 1.0.5 (Docker).missinginside a dict inside a tuple. All 30 outputs load as the expected values in YAML.jl, Ruby Psych, yq, eemeliyaml, and js-yaml. On master, all five parsers get 0 of 30.Test.detect_ambiguities(YAML)reports 1 ambiguity, the same one master has._printmethods takeUnion{Tuple,AbstractSet},Missing, andRational. None overlaps an existing method, andPairis not aTuple.🤖 Generated with Claude Code