Skip to content

fix: add the stdlib fold argument to Time and DateTime - #620

Merged
frostming merged 1 commit into
python-poetry:masterfrom
tuyentran4992:fix-fold-compat
Sep 30, 2026
Merged

frostming merged 1 commit into
python-poetry:masterfrom
tuyentran4992:fix-fold-compat

Conversation

@tuyentran4992

Copy link
Copy Markdown
Contributor

Summary

Fixes #619: Time and DateTime do not accept the stdlib fold argument.

  • item(time(12, 34, 56, fold=1)).fold returns 0 - the fold is silently dropped (same for datetime);
  • item(time(12, 34, 56)).replace(fold=1) raises TypeError on CPython 3.12 (measured);
  • on pure-Python implementations (PyPy, per this issue's traceback) replace() calls type(self)(..., fold=fold), which these constructors reject.

Changes

  • Time.__new__/__init__ and DateTime.__new__/__init__ accept fold: int = 0 - appended after raw, so existing positional call sites are unaffected, and callers pass it by keyword (as the stdlib does); it is forwarded to the stdlib constructor;
  • Time._new/DateTime._new carry fold over in replace() results;
  • item() forwards value.fold when converting datetime/time values.

Tests

Two tests added in tests/test_items.py (test_times_behave_like_times_fold, test_datetimes_behave_like_datetimes_fold) cover construction, item() and replace() round-trips.

Verified on a clean checkout with this patch applied via git apply:

  • tests/test_items.py -> 94 passed
  • full suite -> 1060 passed in 3.23s (Python 3.12, pytest only, unprivileged sandbox)

Agent Drafting Metadata

@frostming
frostming merged commit 49d6efa into python-poetry:master Sep 30, 2026
25 checks passed
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.

Date/time types are missing the fold argument, breaking compatibility with stdlib

2 participants