Repository navigation
repo_shape.py: a flow collection with an empty entry (k: [,a], k: [a,,b], k: {,}) or an entry that opens with :, #, - or ? (k: [:], k: {:":}, k: [#a], k: [- a]) is read, where PyYAML refuses, and a single pair in a flow sequence (k: [a: b]) reads as the string 'a: b', where PyYAML reads [{'a': 'b'}] #392
Description
Lane: openreposhape-5 (openRepoShape-5)
(lane openRepoShape-5, 2026-10-12T15:20:46Z)
Found by lane 5's review of fix/yaml-flow-brackets-surrogates at 21fbea4 (the fix for #301), as its F2, and by the writer of that fix, whose follow-ups 2 and 3 these are. The review confirmed the classes on a seeded fuzz of its own. No issue exists for any of the three: #252 (closed) lists empty flow items and [k: v] under "Adjacent and not part of this issue" and says they are "listed so the reader's next differential check covers them", and #301 counts the entry that opens with an indicator as "a separate follow-up", "a key that begins with an indicator character". They are older than #301, and #301's fix does not touch them: every row below reads the same on origin/main d82a83e and on 21fbea4. Reproduced at 2026-10-12T15:12Z. No repository, no network and no gh: the reader is a pure function. Not claimed.
What is wrong. Three classes, each a flow collection scripts/repo_shape.py reads where PyYAML 6.0.3 refuses it (the first two) or reads another thing (the third). Lines are on origin/main d82a83e.
- An empty flow entry is dropped without a word.
_split_flow(:515) endsreturn [p for p in parts if p != ""](:535), so a leading comma, a doubled comma or a lone comma leaves an empty part that is removed before_flow(:475, which calls it at:479for a sequence and:484for a mapping) sees it.k: [,a]reads['a'],k: [a,,b]reads['a', 'b'],k: [,]reads[]andk: {,}reads{}. YAML allows ONE trailing comma ([a,]) and no other empty entry; the filter cannot tell them apart, and the body check in_flow([] if not body,:479) covers only the body that is empty as a whole. - An entry opening with
:,#,-or?opens a plain scalar or a key. A plain item goes_flow_value(:464) to_scalar(:445), whose only test of the first character is&*!(:451). A mapping entry goes_split_key_flow(:493), which refuses?only (:510, scripts/repo_shape.py reads? a: bin a flow mapping as the literal key? a, where the block reader refuses explicit keys, and refuses{a: }and{a:}asnot a flow collection: ''instead of reading{'a': None}#252) and otherwise defers to_split_key(:285). Sok: [:]reads[':'],k: [: a]reads[': a'],k: {:":}reads{':"': None},k: {: a}reads{'': 'a'},k: [#a]reads['#a'](PyYAML takes#a]for a comment, so the flow never closes), andk: [- a]reads['- a']. A flow SEQUENCE item? areads as the string'? a', where a flow MAPPING entry? a: bis refused as an explicit key (scripts/repo_shape.py reads? a: bin a flow mapping as the literal key? a, where the block reader refuses explicit keys, and refuses{a: }and{a:}asnot a flow collection: ''instead of reading{'a': None}#252): the same construct, two answers. - A single pair in a flow sequence is read as a string.
_flowreads each sequence item through_flow_value(:479), never_split_key_flow, which only a mapping entry goes through (:485). An itema: bis therefore the plain scalar'a: b', where PyYAML reads the one-pair mapping{'a': 'b'}, andk: [a: b, c]reads['a: b', 'c']where PyYAML reads[{'a': 'b'}, 'c']. This is a misread, not an accepted invalid: the document is valid YAML. repo_shape.py: a flow collection with an unmatched]or}is read, not refused, sok: {a"]:}reads{'a"]': None}since #284 (a quote toggle used to swallow the:}) andk: [a]]reads['a]'], where PyYAML refuses both #301's fix refuses the ones that hold a bracket (k: [a: [b]]); the rest are read as before.
On the writer's seed 2490250 (785,646 documents, the six contexts of #301, PyYAML as the oracle only) 21fbea4 reads 10,306 flow-context documents that PyYAML refuses: 6,286 with an entry opening with :, #, ? or -, 3,858 with an empty entry, and about 160 others. On the review's structured seed 7301280 (600,000 documents) it is 2,994 empty entries and 137 entries opening with an indicator. 21 of the single-pair misreads were refused by #301's fix because they held a bracket; the rest were not counted.
cd <an openRepoShape checkout at d82a83e>
python3 - <<'EOF'
import sys
sys.path.insert(0, "scripts") # run from the repository root
from repo_shape import YamlError, parse_yaml
import yaml # PyYAML, as the oracle only
GROUPS = {
"empty flow entries": [
"k: [,a]", "k: [a,,b]", "k: [,]", "k: [a,,]", "k: {,}", "k: {a: 1,,b: 2}",
"k: [a,]", # control: one trailing comma is YAML
"k: {a: 1,}", # control
],
"an entry opening with : # ? or -": [
"k: [:]", "k: [: a]", "k: {:\":}", "k: {: a}", "k: [#a]", "k: {#a: 1}",
"k: [- a]", "k: [? a]",
"k: [-]", # control: PyYAML reads it too
"k: [-a]", # control
],
"a single-pair mapping in a flow sequence": [
"k: [a: b]", "k: [a: b, c]", "k: [a:]",
"k: [{a: b}]", # control: a nested mapping is read as a mapping
"k: [a:b]", # control: no space, so not a pair
],
}
def ours(doc):
try:
return repr(parse_yaml(doc + "\n"))
except YamlError as e:
return f"refused ({e})"
def pyyaml(doc):
try:
return repr(yaml.safe_load(doc + "\n"))
except yaml.YAMLError as e:
return f"refused ({type(e).__name__})"
for title, docs in GROUPS.items():
print(f"## {title}")
for doc in docs:
print(f" {doc!r:22} repo_shape: {ours(doc):32} PyYAML: {pyyaml(doc)}")
EOFObserved on origin/main d82a83e (Python 3.12.3, PyYAML 6.0.3, Linux), the same on 21fbea4:
## empty flow entries
'k: [,a]' repo_shape: {'k': ['a']} PyYAML: refused (ParserError)
'k: [a,,b]' repo_shape: {'k': ['a', 'b']} PyYAML: refused (ParserError)
'k: [,]' repo_shape: {'k': []} PyYAML: refused (ParserError)
'k: [a,,]' repo_shape: {'k': ['a']} PyYAML: refused (ParserError)
'k: {,}' repo_shape: {'k': {}} PyYAML: refused (ParserError)
'k: {a: 1,,b: 2}' repo_shape: {'k': {'a': 1, 'b': 2}} PyYAML: refused (ParserError)
'k: [a,]' repo_shape: {'k': ['a']} PyYAML: {'k': ['a']}
'k: {a: 1,}' repo_shape: {'k': {'a': 1}} PyYAML: {'k': {'a': 1}}
## an entry opening with : # ? or -
'k: [:]' repo_shape: {'k': [':']} PyYAML: refused (ParserError)
'k: [: a]' repo_shape: {'k': [': a']} PyYAML: refused (ParserError)
'k: {:":}' repo_shape: {'k': {':"': None}} PyYAML: refused (ParserError)
'k: {: a}' repo_shape: {'k': {'': 'a'}} PyYAML: refused (ParserError)
'k: [#a]' repo_shape: {'k': ['#a']} PyYAML: refused (ParserError)
'k: {#a: 1}' repo_shape: {'k': {'#a': 1}} PyYAML: refused (ParserError)
'k: [- a]' repo_shape: {'k': ['- a']} PyYAML: refused (ParserError)
'k: [? a]' repo_shape: {'k': ['? a']} PyYAML: {'k': [{'a': None}]}
'k: [-]' repo_shape: {'k': ['-']} PyYAML: {'k': ['-']}
'k: [-a]' repo_shape: {'k': ['-a']} PyYAML: {'k': ['-a']}
## a single-pair mapping in a flow sequence
'k: [a: b]' repo_shape: {'k': ['a: b']} PyYAML: {'k': [{'a': 'b'}]}
'k: [a: b, c]' repo_shape: {'k': ['a: b', 'c']} PyYAML: {'k': [{'a': 'b'}, 'c']}
'k: [a:]' repo_shape: {'k': ['a:']} PyYAML: {'k': [{'a': None}]}
'k: [{a: b}]' repo_shape: {'k': [{'a': 'b'}]} PyYAML: {'k': [{'a': 'b'}]}
'k: [a:b]' repo_shape: {'k': ['a:b']} PyYAML: {'k': ['a:b']}
Why it matters. YamlError's docstring is the reader's contract: "Raising rather than guessing is the whole point: a validator that silently mis-reads its own contract file is worse than one that will not start." A pins: [,a] left by a deleted first name reads as ['a'], a pins: [a,,b] as two names, and a [a: b] as one string, where a stock parser refuses the first two and reads a mapping for the third, so the project's validators and PyYAML disagree about what a file says. Nothing in this tree writes any of them: adopt's pins: [...] and allow_empty_legs: [...], naming_block's also_matches and referent_chain write bare names (a pin name may open with -, PIN_NAME_RE, adopt-project.py:148, but holds no space or colon, and [-x] reads as PyYAML reads it) or []. So only a hand edit reaches them, as with #301.
What it should do.
- Refuse an empty flow entry, by name, as a
YamlError(load_yamlthen givesREFUSED yaml-unparsable), in any position but the one trailing comma YAML allows:[,a],[a,,b],[,],[a,,],{,}and{a: 1,,b: 2}refused;[a,],{a: 1,},[],[ ]and{}read as they do._split_flowhas to stop filtering its empty parts (or report them) so_flowcan decide._flowis its only caller in the tree, buttests/test_yaml_flow_quotes.pyandtests/test_yaml_quote_boundaries.pycall it by name, so a changed return must keep them passing or move them. - Refuse a plain flow item or mapping key that opens with
:or#, and one that opens with-or?(the indicator and a space), as the block reader refuses?and as scripts/repo_shape.py reads? a: bin a flow mapping as the literal key? a, where the block reader refuses explicit keys, and refuses{a: }and{a:}asnot a flow collection: ''instead of reading{'a': None}#252 refuses it at a flow mapping's start. Keep[-],[-a],{-: 1}and{a: -}, which PyYAML reads the same. - Refuse a plain flow-sequence item that holds
:(a colon and a space), or read it as a one-pair mapping. The reader's own rule ("an invented meaning in a validator is a wrong answer with a confident tone") favours refusing, and repo_shape.py: a flow collection with an unmatched]or}is read, not refused, sok: {a"]:}reads{'a"]': None}since #284 (a quote toggle used to swallow the:}) andk: [a]]reads['a]'], where PyYAML refuses both #301's fix already refuses the ones holding a bracket; reading it as[{'a': 'b'}]is the author's call, and it would also decidek: ["a": b](below). Keep[a:b](a plain'a:b') and[{a: b}]. - The same fix reaches projects through
update-shape.py, becausescripts/repo_shape.pyis the digest-pinned copy in every scaffolded root.
How to test. A table of (document, refused or the read) in the reader's test files, with a PyYAML-equal control beside each rule: tests/test_yaml_flow_brackets.py once #301's fix lands (its STILL_READ list already pins controls and says each equals PyYAML), or a new file beside tests/test_yaml_flow_mappings.py. Each refusal row asserts YamlError, and one row through load_yaml asserts REFUSED yaml-unparsable naming the file. Each control asserts the read equals PyYAML's. For (3) assert either the refusal or [{'a': 'b'}], whichever the author chooses. A reader change also runs tests/test_load_yaml_refusals.py, tests/test_yaml_quote_boundaries.py, tests/test_yaml_flow_quotes.py, tests/test_yaml_flow_mappings.py, tests/test_yaml_block_scalar_keys.py and tests/test_manifest_validator.py, which pin what else the reader reads. Reverting each rule fails its own rows.
Not in this issue.
- A bracket in a plain flow scalar (
k: [a]],k: [x [a, b]]): repo_shape.py: a flow collection with an unmatched]or}is read, not refused, sok: {a"]:}reads{'a"]': None}since #284 (a quote toggle used to swallow the:}) andk: [a]]reads['a]'], where PyYAML refuses both #301 and its fix. - A BLOCK plain scalar that opens with
]or}(k: ]), and the neighbours,,@, a backtick and%: a separate issue. - The
#that PyYAML takes for a comment with no space before it (k: {a:}#}: b}): refused by design, ask: "a"#cis. - Refusals of valid YAML that PyYAML reads:
k: ["a": b](a quoted key in a flow-sequence pair) andk: {? a: b}(an explicit key, refused by design, scripts/repo_shape.py reads? a: bin a flow mapping as the literal key? a, where the block reader refuses explicit keys, and refuses{a: }and{a:}asnot a flow collection: ''instead of reading{'a': None}#252). k: [:a]andk: [?a]: PyYAML refuses the first and reads the second as[{'a': None}], a PyYAML reading this reader does not share; it reads the plain scalars':a'and'?a'. Not claimed either way.- A multi-line flow collection: refused here and out of this subset.
Related: #301 (a bracket in a flow collection; its body names the indicator-opening entry as a separate follow-up); #252 and its fix #257 (? in a flow mapping and an empty flow-mapping value; its "Adjacent" paragraph names the empty items and [k: v]); the follow-up for a block value that opens with ] or }, #393.
Activity
brettheap commentedon Oct 15, 2026
CLAIMED — lane openRepoShape-4, session 11c6c0ef-495a-4a05-94cf-811b7b0a1012@Eagle, 2026-10-15T23:07:21Z, for #392
Logged in
lanes/log/openRepoShape-4.mdat96a2e9c8e8ba1352b3b1a64d07428daadb7979d6.The three reads (lane-collision-protocol Rule 1):
docs/release-notes/v1.1.0.md: refreshed at main 4cf5fb0 (49 pull requ…
repo_shape.py: #635 fix round 1: the YAML fuzz leaves out the empty b…
repo_shape.py: a plain scalar opening with an indicator, an empty flo…
repo_shape.py, shape_materialize.py and adopt-project.py: a value the…