Skip to content

Preserve Windows time conversion error classes - #9022

Merged
youknowone merged 4 commits into
RustPython:mainfrom
youknowdot:fix-windows-time-errors
Oct 9, 2026
Merged

youknowone merged 4 commits into
RustPython:mainfrom
youknowdot:fix-windows-time-errors

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Scope

Preserve Python 3.14's exception classes for Windows time.gmtime(), time.localtime(), and time.ctime() conversions.

This draft deliberately starts with a regression-only commit. Its Windows RustPython snippet is expected to fail on the current baseline, which converts UCRT failures to OverflowError. The existing hosted Windows workflow will establish the native baseline before the implementation is added to this same draft branch. Implementation and verification will remain visible in the commit history and checks.

Expected behavior

  • A timestamp representable by time_t but rejected by the Windows C runtime raises OSError with errno.EINVAL, including -1 and 2**40.
  • float(2**63) remains an OverflowError before the OS conversion. The fix must use an exclusive upper bound because signed time_t's maximum rounds up as a float.
  • Existing canonical assertions and skip logic stay unchanged.
  • Python 3.15's negative-time FILETIME fallback and changes to the time64 ABI are outside this draft's scope.

Evidence at draft creation

  • CPython 3.14 pytime.c propagates localtime_s/gmtime_s failures with PyExc_OSError.
  • Microsoft documents gmtime errors and range and localtime EINVAL conditions.
  • The updated existing time snippet passes through the repository's pytest runner on CPython 3.14.7 and the current Linux RustPython baseline, including the float-overflow control. The Windows-specific assertions still require their own hosted result.
  • Normal repository commit hooks pass.

This is a narrow Python 3.14 compatibility extraction from #8954.

AI assistance: OpenAI Codex assisted with source comparison, regression design, implementation preparation, and automated verification under the user's direction. No manual Windows validation is claimed.

Require OSError with EINVAL for representable timestamps rejected by the Windows C runtime, while preserving OverflowError for float(2**63). This initial regression-only commit intentionally exposes the current Windows error mapping before the implementation follows.

AI assistance covered source comparison, regression design, and automated Linux baseline/reference controls. Native Windows results are pending. No human validation is claimed.

Assisted-by: Codex:model-version-unavailable
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6290843b-0989-4b95-ab4e-63e354a3da58

📥 Commits

Reviewing files that changed from the base of the PR and between bd8fdb7 and dfd1eed.


📒 Files selected for processing (5)
  • crates/host_env/src/time.rs
  • crates/stdlib/src/_datetime.rs
  • crates/vm/src/stdlib/time.rs
  • extra_tests/snippets/stdlib_datetime.py
  • extra_tests/snippets/stdlib_time.py

 __________________________________________________
< Are you a real coder or just a pretty committer? >
 --------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

The first hosted regression run failed on CPython 3.14.7 as well as RustPython because a presumed-invalid CRT timestamp succeeded. Add bounded diagnostics before the unchanged assertions to capture full version/build metadata and every conversion result, including negative half-day controls. No implementation or canonical test changes are included.

The existing time snippet still passes the repository pytest runner on Linux CPython 3.14.7 and the current RustPython baseline. Native diagnostic results remain pending.

Assisted-by: Codex:model-version-unavailable
Hosted Windows diagnostics show that CPython 3.14.7 and RustPython both accept gmtime(-1) and gmtime(-43200), while -86400 is rejected by all three converters. Correct only the newly added shared negative test value. CPython raises OSError(errno 22) for every selected rejected value, while the RustPython baseline raises OverflowError. Canonical tests and the recorded diagnostics remain unchanged.

The existing snippet passes both Linux reference and baseline controls. Assisted source investigation and automated verification used no manual validation.

Assisted-by: Codex:model-version-unavailable
Return CRT errno failures from the Windows calendar helpers and translate them to Python OSError. Adapt the datetime caller while retaining its Unix behavior. Use an exclusive signed float upper bound so float(2**63) still raises OverflowError before reaching the CRT.

Keep Windows negative-time FILETIME fallback and time64 ABI changes outside this Python 3.14 extraction. Existing datetime local-error coverage is retained and a UTC error control is added for the observed rejected timestamp -86400.

Hosted native diagnostics prove CPython 3.14.7 raises OSError(errno 22) where the baseline raises OverflowError. Windows-GNU host_env check and warnings-denied Clippy pass. Selected canonical datetime and complete time/datetime snippet Linux controls pass, with six existing baseline canonical skips. Fixed native Windows verification remains pending CI.

AI assistance covered source comparison, implementation, regression design, and automated verification. No manual validation is claimed.

Assisted-by: Codex:model-version-unavailable
@codspeed

codspeed Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing youknowdot:fix-windows-time-errors (dfd1eed) with main (bd8fdb7)

Open in CodSpeed

Footnotes

  1. 4 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. ↩

@youknowone
youknowone marked this pull request as ready for review October 9, 2026 15:41
@youknowone
youknowone merged commit 87aedfb into RustPython:main Oct 9, 2026
30 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T15:48:25.969357Z dfd1eed Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dfd1eedc70

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

try:
converter(timestamp)
except OSError as error:
assert error.errno == errno.EINVAL, (converter, timestamp, error)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove prohibited test logic additions

This adds new assertion/control flow and timestamp data to extra_tests/snippets/stdlib_time.py (and the same commit adds another case to stdlib_datetime.py), but the root policy explicitly forbids changes to test assertions, logic, or data and limits accepted test-file edits to expected-failure decorator changes. Remove these additions (or revise the repository policy first) rather than landing them in the test files.

AGENTS.md reference: AGENTS.md:L273-L279

Useful? React with 👍 / 👎.

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.

2 participants