Skip to content

fix: support datetime.now() in standard execution (#330)#333

Draft
nurikk wants to merge 1 commit intopydantic:mainfrom
nurikk:feature/issue-330-datetime-now
Draft

fix: support datetime.now() in standard execution (#330)#333
nurikk wants to merge 1 commit intopydantic:mainfrom
nurikk:feature/issue-330-datetime-now

Conversation

@nurikk
Copy link
Copy Markdown

@nurikk nurikk commented Apr 14, 2026

Summary

  • Fixes datetime.now() not supported in standard execution #330: datetime.now() previously raised NotImplementedError: OS function 'datetime.now' not implemented with standard execution.
  • Standard (non-iterative) execution now satisfies OsCall::DateTimeNow and OsCall::DateToday by reading the host wall-clock directly, instead of falling through to the unimplemented path.
  • Iterative start/resume callers are untouched — hosts can still inject a deterministic clock via RunProgress::OsCall.

Draft: opening for upstream visibility. Note overlap in scope with #332, which takes a callback-based approach via AbstractOS. Happy to adapt or close in favor of #332.

Approach

  • New host_date_today() / host_datetime_now(tz) helpers in crates/monty/src/os.rs use chrono to produce MontyObject::Date / MontyObject::DateTime. Aware tz mirrors the existing test harness pattern (UTC shifted by fixed offset) and preserves the caller's tz so datetime.tzinfo is tz holds.
  • Executor::run_to_completion in crates/monty/src/run.rs intercepts only the clock variants of FrameExit::OsCall; filesystem/env OS calls still surface as NotImplementedError, preserving the sandbox model.

Test plan

  • New crates/monty/test_cases/datetime__now_standard.py covers naive, UTC, fixed-offset, tz= kwarg, tz=None, and date.today() — passes on Monty and CPython.
  • Pre-fix RED verified: same test failed with the original error.
  • Full datatest suite: 930 passed.
  • cargo test -p monty --features ref-count-panic passes (incl. iterative os_tests.rs).
  • make pytest: 891 passed.
  • cargo clippy ... -D warnings, cargo fmt --check, make lint-py all clean.

Route `OsFunction::DateTimeNow` / `OsFunction::DateToday` through a new
host-clock fallback in `run_to_completion`, so the non-iterative paths
(`MontyRun::run`, REPL `feed_run`) can satisfy `datetime.now()` and
`date.today()` without requiring the caller to wire up suspend/resume
plumbing. The iterative `start`/`resume` path still yields
`RunProgress::OsCall`, preserving deterministic host overrides for
snapshotted workflows.
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 14, 2026

Merging this PR will not alter performance

✅ 15 untouched benchmarks
⏩ 15 skipped benchmarks1


Comparing nurikk:feature/issue-330-datetime-now (b13bcdf) with main (dc44b92)

Open in CodSpeed

Footnotes

  1. 15 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Codecov Report

❌ Patch coverage is 97.22222% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/monty/src/run.rs 88.88% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@samuelcolvin
Copy link
Copy Markdown
Member

I would just fix this for the CLI as you originally suggested in #330.

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.

datetime.now() not supported in standard execution

2 participants