Skip to content

fix: preserve inter-document separators regardless of explicit_start - #318

Open
david-hong-invitae wants to merge 2 commits into
lyz-code:mainfrom
david-hong-invitae:fix/explicit-start-preserve-dividers
Open

fix: preserve inter-document separators regardless of explicit_start#318
david-hong-invitae wants to merge 2 commits into
lyz-code:mainfrom
david-hong-invitae:fix/explicit-start-preserve-dividers

Conversation

@david-hong-invitae

@david-hong-invitae david-hong-invitae commented Aug 5, 2026

Copy link
Copy Markdown

Summary

Fixes #274, #307

explicit_start = false currently removes ALL --- markers including inter-document separators, producing invalid YAML for multi-document files.

Changes

explicit_start = false no longer removes inter-document --- separators. These are structurally required for valid multi-document YAML — removing them merges separate documents into one, breaking the file.

Behavior after this fix:

  • explicit_start: true (default) → adds --- to all documents (unchanged)
  • explicit_start: false → removes leading --- from first document, preserves inter-document --- separators

Implementation

In _ruamel_yaml_fixer, when explicit_start=False means ruyaml won't emit ---, we manually inject ---\n between documents (for i > 0) to keep multi-document YAML valid.

Test Plan

  • explicit_start=False single-doc: leading --- removed ✅
  • explicit_start=False multi-doc: inter-document --- preserved ✅
  • explicit_start=False multi-doc (3 docs): all separators preserved ✅
  • explicit_start=True: behavior unchanged ✅
  • mypy passes (removed stale type: ignore) ✅

David Hong added 2 commits August 5, 2026 14:57
…setting

- Change explicit_start type from bool to Optional[bool]
- Default to None (leave document markers as-is)
- Never remove inter-document --- separators (structurally required)
- explicit_start=False now only affects the first document marker

Fixes lyz-code#274
Fixes lyz-code#307
- Keep explicit_start as bool (default: True), no Optional/None state
- explicit_start=False removes leading --- but ALWAYS preserves
  inter-document --- separators (structurally required for valid YAML)
- Remove unused type: ignore comment (fixes mypy CI)
- Revert test changes that were for the Optional[bool] approach

Fixes lyz-code#274
Fixes lyz-code#307
@Timple

Timple commented Aug 15, 2026

Copy link
Copy Markdown

Would explict_start = keep (or something like it) make sense?

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.

Disabling explicit_start breaks multidocument files

2 participants