Repository navigation
Preserve Unicode strftime output in non-UTF-8 locales #9050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,29 @@ | |
| # print(s) | ||
| assert s == "1970-01-01-00-16-40" | ||
|
|
||
| if sys.platform in ("linux", "darwin"): | ||
| import locale | ||
|
|
||
| old_locale = locale.setlocale(locale.LC_ALL) | ||
| try: | ||
| # Locale output must be Unicode even when the locale is not UTF-8. | ||
| # Keep LC_CTYPE and LC_TIME consistent for wcsftime on macOS. | ||
| # These locales are optional on the host running the snippet. | ||
| for time_locale in ("fr_FR.ISO8859-1", "fr_FR.UTF-8"): | ||
| try: | ||
| locale.setlocale(locale.LC_ALL, time_locale) | ||
| except locale.Error: | ||
| continue | ||
| february = (2024, 2, 1, 12, 0, 0, 3, 32, 0) | ||
| assert time.strftime("%B", february) == "février" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 AGENTS.md reference: AGENTS.md:L273-L279 Useful? React with 👍 / 👎. |
||
| assert ( | ||
| time.strftime("[%B] 🐍 \ud800\0%Y", february) | ||
| == "[février] 🐍 \ud800\0" + "2024" | ||
| ) | ||
| assert time.strftime("%B" * 300, february) == "février" * 300 | ||
| finally: | ||
| locale.setlocale(locale.LC_ALL, old_locale) | ||
|
|
||
| if sys.platform != "wasi": | ||
| # _strptime depends on time.tzname, which is not available on WASI yet. | ||
| x2 = time.strptime(s, "%Y-%m-%d-%H-%M-%S") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit states that it was AI-assisted, but its message ends with prose rather than the mandatory
Assisted-by: AGENT_NAME:MODEL_VERSIONtrailer, 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 👍 / 👎.