GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-155245: Fix calendar failing to import when strftime rejects %OB by tekinertekin · Pull Request #155269 · python/cpython

Conversation

@tekinertekin

@tekinertekin tekinertekin commented Aug 6, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Fixes #155245.

_localized_month stores the format string and only calls strftime from
__getitem__, so _localized_month('%OB') never raises. The first strftime
call happens further down, in the comparison that detects systems which keep
'%OB' as-is — and that comparison sits in the else branch, outside the
try block meant to catch the failure:

try:
    standalone_month_name = _localized_month('%OB')   # no strftime call yet
    ...
except ValueError:                                    # unreachable
    ...
else:
    if len(set(standalone_month_name)) != ...:        # strftime happens HERE

So on a platform whose strftime rejects %OB, the ValueError escapes and
import calendar fails outright. This is not specific to Wine — as written,
the try/except is unreachable on any such platform.

The fix moves the comparison into the try block so the intended fallback to
month_name/month_abbr applies. No behaviour change where %OB works.

Verified locally on a main build (3.16.0a0) by substituting a datetime.date
subclass whose strftime raises ValueError for %O formats, which reproduces
the reported traceback at calendar.py:156 exactly. The added regression test
uses that substitution plus import_helper.import_fresh_module('calendar'), so
it needs no unusual platform: it fails on unpatched main and passes with the
fix. Full test_calendar passes (86 tests) and Tools/patchcheck is 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.

  • Issue: calendar module fails to import on Wine due to incomplete %OB error handling #155245

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tekinertekin
pythongh-155245: Fix calendar failing to import when strftime rejects…
5eaaf29
… %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.
@tekinertekin
tekinertekin requested a review from AA-Turner as a code owner August 6, 2026 10:10
@bedevere-app bedevere-app Bot mentioned this pull request Aug 6, 2026
calendar module fails to import on Wine due to incomplete %OB error handling #155245
Open
@bedevere-app bedevere-app Bot added the awaiting review label Aug 6, 2026
@picnixz picnixz mentioned this pull request Aug 6, 2026
gh-155151: Check the recursion limit in CALL_EX_PY and CALL_KW_BOUND_METHOD #155272
Closed
picnixz
picnixz requested changes Aug 6, 2026
View reviewed changes
Comment thread Lib/test/test_calendar.py
self.assertListEqual(list(calendar.month_abbr),
list(calendar.standalone_month_abbr))

def test_standalone_month_fallback_when_specifier_rejected(self):

@picnixz picnixz Aug 6, 2026

Copy link
Copy Markdown
Member

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 test isn't really relevant. It would be better to find a locale for which we could check the issue directly without mocking.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting changes and removed awaiting review labels Aug 6, 2026
@picnixz

picnixz commented Aug 6, 2026

Copy link
Copy Markdown
Member

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

bedevere-app Bot commented Aug 6, 2026

Copy link
Copy Markdown

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz picnixz closed this Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@picnixz picnixz picnixz requested changes
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting changes

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

calendar module fails to import on Wine due to incomplete %OB error handling

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@tekinertekin @picnixz
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.