feat: implement datetime.time (#331)#334
Draft
nurikk wants to merge 2 commits intopydantic:mainfrom
Draft
Conversation
Adds the `datetime.time` class so `from datetime import time` works and matches CPython's phase-1 surface: - `Type::Time` variant + display as `datetime.time` - `types/time.rs` with narrow-integer storage, constructor validation (`hour`, `minute`, `second`, `microsecond`, `fold`), attribute access, `isoformat()`, CPython-compatible repr/str, hash, `__eq__`/ordering - `StaticStrings::Time` (and `StaticStrings::Fold`) - Module wiring in `modules/datetime.rs` - Consolidated test file `crates/monty/test_cases/time__core.py` tzinfo design choice: accept `None` or a `TimeZone` instance (same scope as the existing `datetime.datetime` implementation), preserving the input object identity so `t.tzinfo is input_tz` holds across attribute access. A full `tzinfo` ABC is out of scope for phase 1 — matches `datetime.rs`. fold is accepted as a keyword argument (0 or 1) and round-tripped through the value so it appears in repr when non-zero and is readable via `.fold`. CPython methods not in phase-1 scope (`replace`, `strftime`, `fromisoformat`, `utcoffset`, `tzname`, `dst`, `__format__`) are not yet implemented — they can be added in a follow-up. On the public-API side, `HeapData::Time` falls back to a repr placeholder in `MontyObject` for now; a dedicated `MontyTime` variant can follow once host bindings need round-tripping.
Merging this PR will not alter performance
Comparing Footnotes
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
from datetime import timeno longer raisesImportError.Type::Time,crates/monty/src/types/time.rs,StaticStrings::Time/Fold, and wirestimeinto thedatetimemodule.datetimetype's scope.Design choices
Noneor aTimeZoneinstance, matching the existingdatetimetype. Stores theHeapIdsot.tzinfo is input_tzholds. A fulltzinfoABC is out of scope (consistent withdatetime).0..=1, exposed on.fold, included in repr when non-zero (matches CPython 3.14). Monty does not interpret fold (no DST model) — round-trip only.replace(),strftime(),fromisoformat(),utcoffset(),tzname(),dst(),__format__,min/max/resolution, andMontyTimein the publicMontyObjectserde enum (falls back to repr at the PyO3/JS boundary).Test plan
crates/monty/test_cases/time__core.pycovers construction, attribute access,isoformat(), repr/str, equality/ordering, hashability, truthiness, awaretzinfosemantics,fold, and CPython-compatible error messages — passes on Monty and CPython.cargo test -p monty --features ref-count-panic: 596 passed, 19 ignored.cargo clippy --workspace --tests --all-features -- -D warningsclean.cargo fmt --check,ruff check/ruff format --checkclean.