gh-155245: Fix calendar failing to import when strftime rejects %OB - #155269
gh-155245: Fix calendar failing to import when strftime rejects %OB#155269tekinertekin wants to merge 1 commit into
Conversation
… %OB
_localized_month stores the format string and calls strftime lazily from
__getitem__, so constructing _localized_month('%OB') never raises. The
first strftime call happens further down, while comparing the standalone
names against the regular ones to detect systems that keep '%OB' as-is --
and that comparison sits in the else branch, outside the try block meant
to catch the failure. On a platform whose strftime rejects '%OB' the
ValueError therefore escaped and importing calendar failed outright.
Move the comparison into the try block so the intended fallback to
month_name/month_abbr applies.
| self.assertListEqual(list(calendar.month_abbr), | ||
| list(calendar.standalone_month_abbr)) | ||
|
|
||
| def test_standalone_month_fallback_when_specifier_rejected(self): |
There was a problem hiding this comment.
This test isn't really relevant. It would be better to find a locale for which we could check the issue directly without mocking.
|
I consider a PR entirely written by an agent as not acceptable. The contribution should be credited to the agent in this case. We do not want to encourage users to use agents just to add a contribution line in their CV. We rather encourage human-driven contributions than automated ones. |
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Fixes #155245.
_localized_monthstores the format string and only callsstrftimefrom__getitem__, so_localized_month('%OB')never raises. The firststrftimecall happens further down, in the comparison that detects systems which keep
'%OB'as-is — and that comparison sits in theelsebranch, outside thetryblock meant to catch the failure:So on a platform whose
strftimerejects%OB, theValueErrorescapes andimport calendarfails outright. This is not specific to Wine — as written,the
try/exceptis unreachable on any such platform.The fix moves the comparison into the
tryblock so the intended fallback tomonth_name/month_abbrapplies. No behaviour change where%OBworks.Verified locally on a
mainbuild (3.16.0a0) by substituting adatetime.datesubclass whose
strftimeraisesValueErrorfor%Oformats, which reproducesthe reported traceback at
calendar.py:156exactly. The added regression testuses that substitution plus
import_helper.import_fresh_module('calendar'), soit needs no unusual platform: it fails on unpatched
mainand passes with thefix. Full
test_calendarpasses (86 tests) andTools/patchcheckis clean.AI tools were used on this PR: Claude Code (Opus) located the cause, wrote the
patch and the test, and ran the verification. I reviewed the change, understand
it and can explain it, and I take responsibility for it.