Skip to content

✨ Resolve timestamps in round-trip mode under OPT_TIMESTAMPS#218

Merged
frenck merged 2 commits into
mainfrom
frenck/roundtrip-timestamps
Jul 5, 2026
Merged

✨ Resolve timestamps in round-trip mode under OPT_TIMESTAMPS#218
frenck merged 2 commits into
mainfrom
frenck/roundtrip-timestamps

Conversation

@frenck

@frenck frenck commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Breaking change

None. Extends an existing opt-in flag to another mode; default behavior is unchanged.

Proposed change

Follow-up to #216: the standalone OPT_TIMESTAMPS flag now resolves timestamps in round-trip mode as well as on the fast path. to_dict(), indexing, walk(), and keys() on a YAMLRocksDocument return a date/datetime when the flag (or OPT_PYYAML_COMPAT, which implies it) is set, while the source still re-emits byte-for-byte.

Before this, round-trip typed-timestamp resolution followed the schema, so it was active only under OPT_PYYAML_COMPAT; the standalone flag was a fast-path feature. Now the two paths agree.

  • Threads a resolve_timestamps flag through the round-trip AST read conversion (node_to_python_* and the document read helpers), stored on the YAMLRocksDocument and set from the load options. Only plain, untagged scalars resolve, and a quoted "2024-01-15" stays a string, matching the fast path.
  • Emission is untouched, so an unmodified document still re-emits byte-for-byte (verified against the full real-world corpus).
  • Annotated mode (OPT_ANNOTATED) deliberately stays schema-driven: it resolves timestamps under OPT_PYYAML_COMPAT (to a plain date/datetime, no source location) but not from the standalone flag. Documented in the options reference.

Type of change

  • Dependency or tooling upgrade
  • Bugfix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Deprecation (replaces or removes a feature, with a migration path)
  • Breaking change (a fix or feature that changes existing behavior)
  • Code quality, refactor, or test-only change
  • Documentation only

Additional information

Checklist

  • I have read the AI Policy, and this pull request was not created by an autonomous agent.
  • I fully understand the code in this pull request and can explain every line, including any AI-assisted changes.
  • The change is covered by tests, and uv run pytest passes locally. A pull request cannot be merged unless CI is green.
  • uv run ruff check . and uv run ruff format --check . pass.
  • cargo fmt --check and cargo clippy --all-targets -- -D warnings pass.
  • Round-trip fidelity is preserved: an unmodified document still re-emits byte-for-byte.
  • No commented-out or dead code is left in the pull request.

If the change is user-facing:

  • Documentation under docs/ is added or updated, and docs/verify_examples.py still passes.

Copilot AI review requested due to automatic review settings July 5, 2026 08:46
@frenck frenck added the new-feature New features or options. label Jul 5, 2026
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR introduces a resolve_timestamps boolean flag that is derived from OPT_TIMESTAMPS/OPT_PYYAML_COMPAT in loads() and threaded through YAMLRocksDocument (new field and with_resolve_timestamps builder) into round-trip read/write paths (__len__, __getitem__, __setitem__, __delitem__, keys(), to_dict(), walk()). Core value-conversion functions in src/roundtrip/value.rs (node_to_python_with, node_to_python_cached, scalar_to_py, node_to_python_key) gain the flag to control whether plain scalars resolve to date/datetime. annotate.rs call sites are updated to pass an explicit schema == Schema::Yaml11PyYaml boolean. Documentation and a test covering the standalone OPT_TIMESTAMPS flag were updated accordingly.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant loads
  participant loads_roundtrip
  participant YAMLRocksDocument
  participant node_to_python_with

  Caller->>loads: loads(data, OPT_ROUND_TRIP | OPT_TIMESTAMPS)
  loads->>loads_roundtrip: resolve_timestamps flag
  loads_roundtrip->>YAMLRocksDocument: with_resolve_timestamps(flag)
  Caller->>YAMLRocksDocument: to_dict() / __getitem__ / walk()
  YAMLRocksDocument->>node_to_python_with: convert(node, resolve_timestamps)
  node_to_python_with-->>YAMLRocksDocument: date/datetime or raw value
  YAMLRocksDocument-->>Caller: resolved result
Loading

Possibly related PRs

  • frenck/YAMLRocks#116: Modifies the same round-trip projection plumbing in src/roundtrip/document.rs/src/roundtrip/value.rs, threading extra context through node-to-Python conversion and mapping key matching/lookup.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: resolving timestamps in round-trip mode under OPT_TIMESTAMPS.
Description check ✅ Passed The description matches the implemented timestamp-resolution changes and the documentation/test updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codspeed-hq

codspeed-hq Bot commented Jul 5, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing frenck/roundtrip-timestamps (b9f0455) with main (eea7911)

Open in CodSpeed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR is a follow-up to #216 that extends the standalone OPT_TIMESTAMPS flag so it also resolves plain, untagged timestamp scalars to Python date/datetime objects in round-trip mode, not just on the fast path. Previously round-trip timestamp typing was schema-driven (active only under OPT_PYYAML_COMPAT); now the fast and round-trip paths agree, while emission stays untouched so unmodified documents still re-emit byte-for-byte. A resolve_timestamps boolean is threaded through the round-trip AST read conversion and stored on YAMLRocksDocument, derived from the load options. Annotated mode deliberately remains schema-driven.

Changes:

  • Threads a resolve_timestamps flag through node_to_python_* / document read helpers (to_dict, indexing, walk, keys, len, key matching), stored on YAMLRocksDocument and set from load options.
  • Switches the round-trip scalar_to_py gate from schema == Schema::Yaml11PyYaml to the new flag; annotated-mode call sites explicitly pass schema == Schema::Yaml11PyYaml to keep their schema-driven behavior.
  • Updates the timestamps test and the options reference documentation.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/roundtrip/value.rs Adds resolve_timestamps parameter through the conversion helpers and gates timestamp resolution on it.
src/roundtrip/document.rs Stores the flag on YAMLRocksDocument, adds with_resolve_timestamps, and threads it through every read helper and both view/node accessors.
src/ffi/mod.rs Passes the derived resolve_timestamps into loads_roundtrip and sets it on the document.
src/ffi/convert/annotate.rs Preserves annotated-mode schema-driven resolution by passing schema == Schema::Yaml11PyYaml.
docs/src/content/docs/reference/options.md Updates prose to describe round-trip resolution (summary table row still stale — see comment).
tests/features/test_timestamps.py Replaces the "keeps strings" test with one asserting round-trip resolution under the standalone flag.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +94 to +96
the other 1.1 footguns. It applies to `loads`/`load` and to round-trip mode, so
`to_dict()`, indexing, `walk()`, and `keys()` on a `YAMLRocksDocument` all resolve
timestamps too (the source still re-emits byte-for-byte). In annotated mode,
Comment thread tests/features/test_timestamps.py Outdated
@codecov-commenter

codecov-commenter commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.95402% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.51%. Comparing base (eea7911) to head (b9f0455).

Files with missing lines Patch % Lines
src/roundtrip/document.rs 88.69% 19 Missing ⚠️
src/roundtrip/value.rs 96.15% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #218      +/-   ##
==========================================
- Coverage   92.53%   92.51%   -0.03%     
==========================================
  Files          41       41              
  Lines       12520    12720     +200     
==========================================
+ Hits        11586    11768     +182     
- Misses        934      952      +18     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
tests/features/test_timestamps.py (1)

118-126: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Docstring spans two lines; guideline calls for one-line docstrings.

The docstring wraps across two physical lines rather than fitting on one. As per coding guidelines, "Every Python test has a one-line docstring describing what it verifies."

✏️ Proposed fix
 def test_round_trip_with_standalone_flag_resolves():
-    """The standalone OPT_TIMESTAMPS flag also resolves in round-trip mode, across
-    to_dict, indexing, and walk, while the source re-emits byte-for-byte."""
+    """The standalone OPT_TIMESTAMPS flag also resolves timestamps in round-trip mode."""

Aside from the docstring formatting, the assertions correctly exercise to_dict(), indexing, walk(), and byte-for-byte to_yaml() re-emission, consistent with the resolve_timestamps wiring in src/roundtrip/document.rs.

Source: Path instructions

src/roundtrip/document.rs (1)

166-237: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding targeted tests for the new timestamp-aware mutation/key paths.

Codecov reports 19 missing lines / 88.69% patch coverage concentrated in this file. The resolve_timestamps threading through set_child/del_child/distinct_keys (key matching against a resolved date/datetime, duplicate-key dedup under timestamp resolution) is exactly the kind of edge-case logic worth covering explicitly — e.g. doc[date(2024,1,15)] = ... or del doc[...] against a plain timestamp key when OPT_TIMESTAMPS is set.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a3f65472-796c-49d7-a13d-f4035680d962

📥 Commits

Reviewing files that changed from the base of the PR and between eea7911 and b9f0455.

📒 Files selected for processing (6)
  • docs/src/content/docs/reference/options.md
  • src/ffi/convert/annotate.rs
  • src/ffi/mod.rs
  • src/roundtrip/document.rs
  • src/roundtrip/value.rs
  • tests/features/test_timestamps.py

@frenck frenck merged commit d3e22f4 into main Jul 5, 2026
73 checks passed
@frenck frenck deleted the frenck/roundtrip-timestamps branch July 5, 2026 09:45
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

new-feature New features or options.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants