Skip to content

Fix serialization of dates and times created by factory methods - #707

Open
liugedragon wants to merge 1 commit into
python-poetry:masterfrom
liugedragon:fix/date-time-factory-serialization
Open

liugedragon wants to merge 1 commit into
python-poetry:masterfrom
liugedragon:fix/date-time-factory-serialization

Conversation

@liugedragon

Copy link
Copy Markdown

Summary

Date.fromisoformat(), Date.fromordinal() and the other inherited date factories return TOML items with an empty _raw value. Time.fromisoformat() does the same. Serializing one produces value = \n, which both Tomlkit and stdlib tomllib reject.

When no source text was supplied, generate the date's ISO text or use the existing local-time formatter. This follows the fallback already used by DateTime; parsed items retain their original text and comments.

Fifteen regressions cover date/time factories, fractional seconds, existing raw formatting and the unchanged DateTime behavior. On Python 3.11+, serialization is checked with the independent stdlib parser as well as Tomlkit. Before the fix: 11 failed, 4 passed. After the fix: all pass.

Validation on Windows / Python 3.13.4:

  • Full suite including the pinned toml-test submodule: 1,449 passed.
  • All six configured pre-commit hooks: passed.
  • New test file Mypy: passed. Full-tree Mypy reports the same 33 existing diagnostics on both base and patch.

Duplicate Check

Agent Drafting Metadata

  • Agent: OpenAI Codex
  • Model: GPT-6 family; the exact variant is not exposed by this session.
  • Notes: The implementation and regression tests were agent-authored. The validation commands above were executed locally.

@human-attestation

Copy link
Copy Markdown

🛡️ Human Attestation required. A human needs to confirm this PR once before it can merge.

Attest this PR — sign in with GitHub, pass the challenge, and confirm one of the statements.

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.

1 participant