Skip to content

Declare nullable datetime defaults directly - #9559

Merged
youknowone merged 2 commits into
RustPython:mainfrom
youknowdot:cleanup-datetime-defaults-20261103
Nov 3, 2026
Merged

youknowone merged 2 commits into
RustPython:mainfrom
youknowdot:cleanup-datetime-defaults-20261103

Conversation

@youknowdot

@youknowdot youknowdot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Declare five nullable datetime defaults with Option<PyObjectRef> and default = None: time/datetime constructor tzinfo, and now, fromtimestamp, astimezone tz.

Omission remains a native absent state. The three methods still create a None reference lazily at the same body fallback. Timezone validation, callback order and pickle-slot branches stay in their existing locations. Rendered signatures are unchanged; typed None metadata replaces Raw metadata.

The earlier three string-default changes have been restored. Both timespec arguments and the datetime separator keep their Missing paths, which avoid default-object construction, string copying and separator validation work on omission. The other 25 sentinel/display overrides also remain unchanged.

Reviewed against CPython 3.15.0 d220409a13b77de7a6c30abe16ea90db01528edc datetime source. This PR is independent of the other default-cleanup PRs.

Validation

  • Independent exact-head source review, normal pre-commit hooks, rustfmt and diff checks passed for 1d5d31e42de8cefecb182d4f00d78a0e20e49cbf.
  • No test assertions, test files or Lib files changed.
  • Workspace/C-API tests and Clippy, plus canonical test_datetime, were attempted offline on this head. All stopped before compilation because the pinned parking_lot_core git dependency is unavailable locally. No local native test pass is claimed.
  • CI for this head is pending. Actual canonical test_datetime outcomes on the three operating systems remain to be checked.

AI-assisted implementation and review with OpenAI Codex; model version not exposed.

Summary by CodeRabbit

  • Bug Fixes
    • Time and date functions now consistently treat an omitted timezone argument as None, while retaining existing timezone handling when a value is provided.

Use Option None for five timezone arguments, typed auto defaults for two timespec arguments, and a raw Python T default for the datetime separator. Preserve supplied separator validation in the method body, timezone checks, pickle constructors, and every unchanged/timedelta omission sentinel.

Source-reviewed against CPython 3.15.0 d220409a13b77de7a6c30abe16ea90db01528edc. No test expectations or Lib files changed. Local native validation remains limited by the available dependency closure.

Assisted-by: OpenAI Codex:model version not exposed
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

Timezone parameters in datetime constructors and methods now use Option<PyObjectRef> with None as the default. Consumers pass Python None when the option is absent.

Changes: Datetime timezone arguments

Layer / File(s) Summary
Time and datetime constructors
crates/stdlib/src/_datetime.rs
TimeArgs and DateTimeArgs use optional timezone values. Their constructors pass the values through timezone conversion.
Datetime methods
crates/stdlib/src/_datetime.rs
now, fromtimestamp, and astimezone use optional timezone values and substitute Python None when absent.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Refactor

Suggested reviewers: youknowone

Merge Risk: Minimal · up to 1d5d3

The changes preserve timezone argument behavior and public signatures. No actionable merge-blocking issue was identified; normal build and test checks should complete before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: declaring nullable datetime defaults directly.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 1 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ast-grep (0.51.1)

ast-grep could not parse rule config: /ast-grep-rules/ast-grep-essentials/rules/cpp/security/libxml2-audit-parser-cpp.yml

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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 0a88bee and 1d5d31e.

Files selected for processing: 1
  • crates/stdlib/src/_datetime.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

Restore runtime defaults whose concrete literal lowering adds Python object creation, conversion, or reference management on omitted arguments. Keep only cost-preserving None default cleanup, where applicable. No test code or expectations changed.

Assisted-by: OpenAI Codex:model version not exposed
@youknowdot youknowdot changed the title Declare concrete datetime argument defaults directly Declare nullable datetime defaults directly Nov 3, 2026
@youknowone
youknowone marked this pull request as ready for review November 3, 2026 04:20
@youknowone
youknowone enabled auto-merge (squash) November 3, 2026 04:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 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-11-03T04:22:35.717664Z 1d5d31e 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.

@youknowone
youknowone merged commit 7d4cc50 into RustPython:main Nov 3, 2026
28 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.

3 participants