Skip to content

Preserve temporal fold during copying and pickling - #650

Open
xiehuanyi wants to merge 3 commits into
python-poetry:masterfrom
xiehuanyi:fix-temporal-pickle-fold
Open

xiehuanyi wants to merge 3 commits into
python-poetry:masterfrom
xiehuanyi:fix-temporal-pickle-fold

Conversation

@xiehuanyi

Copy link
Copy Markdown

Summary

Copying or pickling a DateTime item created from an ambiguous local datetime drops fold=1. For example, the later 01:30 during a DST rollback becomes the earlier 01:30, changing the timestamp by an hour while retaining the original rendered TOML. Time items also lose their fold.

Preserve fold in the datetime and time pickle constructor arguments for protocols 4 and later, matching PEP 495 and the standard-library types. This also fixes shallow and deep copying. Default fold-zero values keep their original pickle bytes and constructor representation. Tests compare all supported pickle protocols with the corresponding stdlib value, check both fold values, and retain the rendered value and comment trivia. The existing fold-sensitive timezone fixture is moved to module scope so it can be pickled.

Validation on Linux / CPython 3.12.13:

  • New tests on the original source: 8 failures and 24 passing controls.
  • Complete Tomlkit suite, including its pinned toml-test corpus: 1,130 passed.
  • All six applicable pre-commit hooks passed; wheel and sdist built.
  • Mypy reports the same 29 diagnostics on the baseline and this patch.
  • Current Poetry tests using this source: 3,310 passed, 34 skipped, 2 expected failures.
  • Current Poetry-core tests using the vendored source: 2,950 passed, 7 skipped, 9 benchmark cases excluded by its test configuration.

Other platforms and Python versions were not run locally.

Agent Drafting Metadata

  • Agent: OpenAI Codex
  • Model: gpt-6.1-sol (xhigh)
  • Notes: Assisted with investigation, implementation and regression tests. The exact patch and local evidence were independently reviewed before publication.

Copilot AI balanced review requested due to automatic review settings October 12, 2026 10:32

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.

96 datetime/time copy and pickle checks passed across naive, UTC and America/New_York zones, fold=0/fold=1, pickle protocols 0–5, copy.copy and copy.deepcopy. I used Python 3.12.14 against commit a49c951.

Protocols 4/5 and both copy operations preserved fold, while protocols 0–3 lost it consistently with the standard-library temporal types. Serialized text and tzinfo were preserved in these cases. The New York fold=1 datetime is a useful regression because losing fold changes its UTC offset, not just an attribute. These were standalone assertions against fetched PR source, not a full pytest run.

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