Skip to content

Preserve temporal serialization in reflected addition - #652

Open
xiehuanyi wants to merge 1 commit into
python-poetry:masterfrom
xiehuanyi:fix/reflected-temporal-addition-20261012-r2
Open

xiehuanyi wants to merge 1 commit into
python-poetry:masterfrom
xiehuanyi:fix/reflected-temporal-addition-20261012-r2

Conversation

@xiehuanyi

Copy link
Copy Markdown

Summary

timedelta + Date returns the correct date with an empty serialized value, so assigning it back to a document produces invalid TOML. timedelta + DateTime formats correctly but loses its original trivia. Both operations bypass the wrappers' existing addition methods.

Route reflected addition through the existing wrapped addition for both temporal types. Six cases cover forward/backward shifts of dates and naive/aware datetimes, matching ordinary addition's value, text and trivia and round-tripping the resulting document.

Validation: all six regressions fail on the unchanged source; all 1190 tests including conformance fixtures and applicable pre-commit checks pass after the change. The six existing Mypy diagnostics remain unchanged from the exact base, allowing for shifted line numbers.

Agent Drafting Metadata

  • Agent: OpenAI Codex
  • Model: GPT-6.1 Sol, xhigh
  • Notes: This description and changes in tomlkit/items.py, tests/test_items.py and CHANGELOG.md were prepared with this agent.

Copilot AI balanced review requested due to automatic review settings October 12, 2026 19:40

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Wkhanex Wkhanex 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.

Nine reflected-addition checks passed for dates, offset datetimes and local datetimes, including negative one-day, positive one-day and 27-hour-plus-one-microsecond deltas. I used Python 3.12.14 against commit 0b667c6.

For every case, delta + item and item + delta had the same TOML class, value and as_string output. Assigning the reflected result back into a commented document produced valid TOML with the comment intact, and stdlib tomllib decoded the expected temporal value. This checks the document-assignment path as well as the numeric result. I ran standalone assertions against fetched PR source; I did not run the full pytest suite.

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.

3 participants