Skip to content

scripts/repo_shape.py: a block scalar's indentation digit (|2, >-2) is still read with the digit ignored, and four more block-scalar layouts are read otherwise than YAML reads them #1004

Closed

Description

@brettheap

Goal: scripts/repo_shape.py's YAML reader reads a block scalar as YAML does, or refuses it by its line, for a header that holds an indentation digit (|2, |1, >-2) and for four layouts it reads otherwise today (|+, a spaces-only line deeper than the block, a leading such line, and a tab line).

Filed by lane openRepoShape-3, from RV974's review of #974 (comment 6271630963).

State. Read at origin/main 6f27432c, and at #974's head dc82a4c4 (open, a draft, found READY by RV974) where it is said. Every row below reads the same at both, so none of it waits on #974. The line numbers are #974's head; at main the same code is _BLOCK_HEADER_RE at :804, _block_scalar_body at :890 (the blank test at :905, the first line's column at :912-913) and _block_scalar_text at :940 (header.endswith("-") at :951).

What happens. Two groups. In each, this reader returns a text without a word where YAML returns another text or refuses the document. No tool writes a block scalar, so each comes from a hand-written file.

RV974's SHOULD-1, the digit. A header's indentation digit is accepted and never read: the block's column is the first line's. #974 refuses the one document where a later line is shallower than the first, and its body had said the case was "now refused ... and not misread", which is true of that example only. With no line shallower than the first, the digit is still ignored (head against PyYAML 6.0.3; main reads each the same):

k: |2 over "    a", "    b"  -> head {'k': 'a\nb\n'}, PyYAML {'k': '  a\n  b\n'}
k: |1 over "  a", "  b"      -> head 'a\nb\n',       PyYAML ' a\n b\n'
k: >-2 over "    a", "    b" -> head 'a b\n' (the `-` is not honoured either), PyYAML '  a\n  b'

RV974's second NIT, four layouts that already disagreed with PyYAML at main and still do. Lane 3 wrote each as a document and ran it again at dc82a4c4 and at 6f27432c, with PyYAML 6.0.3 on Python 3.12.3 (parse_yaml over the text, no tool run); the two copies read each the same. Each quoted string is one line of the document after k:, and \t is a tab:

1   k: |+ over "  a", ""                -> head 'a\n',      PyYAML 'a\n\n'
2   k: | over "  a", "    ", "  b"      -> head 'a\n\nb\n', PyYAML 'a\n  \nb\n'
3   k: | over "      ", "  a"           -> head '\na\n',    PyYAML refuses
4a  k: | over "  a", "\t", "  b"        -> head 'a\n\nb\n', PyYAML refuses
4b  k: | over "  a", " \t", "  b"       -> head 'a\n\nb\n', PyYAML refuses
  • 1: |+ is read as clip, so the blank lines it keeps are dropped and one newline stays. With two blank lines and z: 1 after, the head reads 'a\n' and PyYAML 'a\n\n\n'.
  • 2: a spaces-only line deeper than the block (four spaces in a block of two) is a blank line to this reader and loses the two spaces YAML keeps.
  • 3: a LEADING spaces-only line deeper than the first text line is read as blank. PyYAML refuses the document.
  • 4a, 4b: a tab-only line, or fewer spaces than the block's column and then a tab, inside a block is read as blank. PyYAML refuses both.
  • Not on RV974's list, measured for this issue: spaces to the block's own column and then a tab (k: | over a, \t, b) is no refusal in PyYAML, which reads the tab as text, 'a\n\t\nb\n'; this reader reads 'a\n\nb\n'. A rule that refused every line holding a tab would refuse a document YAML reads.

Evidence.

Direction.

Verify.

Size. Small if each layout is refused by its line: one header rule, up to four refusals in _block_scalar_body, and nine test rows. Medium if |+ and the deeper spaces-only line are read as YAML reads them, because _block_scalar_text and _fold_block_body then carry the kept lines.

Lane: openreposhape-3 (openRepoShape-3)

Activity

  1. added this to the v1.2.0 milestone on Oct 19, 2026
  2. brettheap commented on Oct 19, 2026

    @brettheap
    ContributorAuthor

    CLAIMED — lane openRepoShape-3, session b30e8b49-f249-4668-adb1-1dbfa93c09e1@Eagle, 2026-10-19T22:26:16Z, for #1004

    Logged in lanes/log/openRepoShape-3.md at 75fb6a72275414f212bf498816433faed0c8e5ff.

    The three reads (lane-collision-protocol Rule 1):

    1. existing `CLAIMED —` comments on opensoft/openRepoShape#1004:
       none
    2. `gh pr list --repo opensoft/openRepoShape --state all --search "#1004"`, kept where the row or its body names `#1004`:
       #974
    3. `git ls-remote --heads [email protected]:opensoft/openRepoShape` branches naming `1004` as a whole token:
       none
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions