Skip to content

Preserve Unicode strftime output in non-UTF-8 locales - #9050

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-strftime-locale-unicode
Oct 10, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix-strftime-locale-unicode

Conversation

@youknowdot

@youknowdot youknowdot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Extract the independent Linux/macOS strftime locale-output fix from #8954 (43065e79ddc46eafeca58cb39398ac007b5d25f7) onto Python 3.14 main (3af5f8a15314446d2b28a90e429c938dc7b8beeb).

Use wcsftime on Linux and macOS rather than interpreting narrow libc output as UTF-8. This preserves localized month/day text when the selected locale uses another encoding. Windows is unchanged, and other Unix targets retain the existing narrow fallback, including OpenBSD.

The production hunks are taken directly from the pinned mega PR and match CPython 3.14.7's wide-formatting path. No Python 3.15 behavior or unrelated migration changes are included. Searches found no dedicated duplicate; merged #7090 is Windows-specific, and #7671 covers earlier Unicode literal passthrough.

Add bounded coverage to the existing time snippet for localized output, Unicode/surrogate/NUL composition, and buffer growth. Save/set/restore LC_ALL, since macOS's libc conversion also depends on LC_CTYPE. Locales remain optional for hosts where they are not installed; the local verification explicitly exercised both rather than silently skipping them.

Validation

  • Exact CPython 3.14.7: complete updated snippet passes; both French ISO-8859-1 and UTF-8 locale paths executed.
  • Unchanged native main fails the new localized-month assertion; this head passes the full snippet and its pytest entry.
  • Native proof explicitly verifies both LC_TIME and LC_CTYPE are set to each requested locale and produces the correct Unicode month in both encodings.
  • All 5 existing canonical TimeTestCase strftime tests pass, including Unicode/surrogate/NUL and format/bounds checks.
  • Host-environment Clippy and separate C-API Clippy with warnings denied; normal repository commit hooks.
  • Independent source review checked the FFI signature, platform wchar_t layout, initialized buffers, lengths, lifetimes and growth, and caught/corrected the macOS locale-category test assumption.

No canonical assertions, implementation-name guards, or README text were changed; no Rust behavioral tests were added. Native validation is Linux-only, not a complete workspace or macOS execution claim. Full hosted CI is pending; this remains a draft for review.

AI-assisted implementation and validation with OpenAI Codex; model identifier unavailable. No human review is implied.

Summary by CodeRabbit

  • Bug Fixes
    • Date and time formatting on Linux and macOS now better supports Unicode, including non-English month names and emoji in format strings.
    • Invalid characters in formatted output are replaced safely, and longer formatted results are supported.
    • Embedded NUL characters in format strings are rejected. Other Unix platforms retain their existing formatting behavior.

Assisted-by: OpenAI Codex:model identifier unavailable
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b29e5231-7e55-40e7-b708-1d969380b8c9

📥 Commits

Reviewing files that changed from the base of the PR and between 3af5f8a and fd23fb6.


📒 Files selected for processing (2)
  • crates/host_env/src/time.rs
  • extra_tests/snippets/stdlib_time.py

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



📝 Walkthrough

Walkthrough

Linux and macOS now use wcsftime for strftime formatting. The implementation handles embedded NUL formats, grows the output buffer, and replaces values that cannot be represented as Unicode. Tests cover available French locales.

Changes

Unicode strftime

Layer / File(s) Summary
Wide-character formatting and validation
crates/host_env/src/time.rs, extra_tests/snippets/stdlib_time.py
Linux and macOS use wcsftime; other Unix targets retain narrow strftime. Tests check formatting with available French locales, including Unicode and special characters.

Priority: ➖ Normal

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

Change: Bug fix

Suggested reviewers: youknowone


Merge Risk: ⚪ Minimal · up to fd23f

This change preserves localized Unicode strftime output on Linux and macOS. No actionable merge-blocking risk was identified; hosted CI and macOS validation remain pending.

Pre-merge checks | Passed 5
✅ Passed checks (5 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: preserving Unicode output from strftime in non-UTF-8 locales.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files.
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.

✨ 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.

@youknowone
youknowone marked this pull request as ready for review October 10, 2026 10:58
@youknowone
youknowone enabled auto-merge (squash) October 10, 2026 10:58
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 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-10T11:04:19.851627Z fd23fb6 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: fd23fb61de

ℹ️ 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".

}

#[cfg(windows)]
// These Unix platforms provide wcsftime, which returns locale text as Unicode.

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 Add the required AI-assistance trailer

This commit states that it was AI-assisted, but its message ends with prose rather than the mandatory Assisted-by: AGENT_NAME:MODEL_VERSION trailer, so it does not meet the repository's critical disclosure policy; add the prescribed trailer before landing.

AGENTS.md reference: AGENTS.md:L20-L23

Useful? React with 👍 / 👎.

except locale.Error:
continue
february = (2024, 2, 1, 12, 0, 0, 3, 32, 0)
assert time.strftime("%B", february) == "février"

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 the prohibited test logic

The newly added locale block changes test data, control flow, and assertions in an existing snippet test, but the repository's critical test-file policy permits only expected-failure decorator and associated TODO edits. Drop this regression block rather than modifying stdlib_time.py as part of the fix.

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

Useful? React with 👍 / 👎.

@youknowone
youknowone merged commit eb162b4 into RustPython:main Oct 10, 2026
30 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.

2 participants