python / python/cpython

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

オープン
#155,245 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

OS-unsupported stdlib type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

Component: Library (Lib)
Type: bug
Python Version: 3.15

Summary:

The calendar module added in Python 3.15 (gh-131146) fails to import when running
under Wine because the error handling for unsupported %OB/%Ob format specifiers
is incomplete.

The try/except block catches ValueError during _localized_month object construction,
but the actual strftime call happens lazily in getitem when set() iterates
over the sequence in the else block.

Steps to Reproduce:

  1. Run Python 3.15 under Wine (any version 9.0-11.14)
  2. Execute: import calendar

Expected Result:

calendar module imports successfully, falling back to month_name/month_abbr
when %OB/%Ob are not supported

Actual Result:

Traceback (most recent call last):
File "", line 1, in
File "calendar.py", line 156, in
File "calendar.py", line 110, in getitem
ValueError: Invalid format string

Analysis:

In Lib/calendar.py lines 143-156:

try:
standalone_month_name = _localized_month('%OB')
standalone_month_abbr = _localized_month('%Ob')
except ValueError:
standalone_month_name = month_name
standalone_month_abbr = month_abbr
else:
# This calls getitem which triggers the actual strftime call
if len(set(standalone_month_name)) != len(set(month_name)): # <-- ValueError here
standalone_month_name = month_name

The _localized_month constructor just stores the format string; the actual
datetime.strftime() call happens in getitem when set() iterates. Wine's
strftime doesn't support %O and raises ValueError at this point, which is
not caught.

Suggested Fix:

Wrap the set() comparison in the else block with try/except:

try:
standalone_month_name = _localized_month('%OB')
standalone_month_abbr = _localized_month('%Ob')
except ValueError:
standalone_month_name = month_name
standalone_month_abbr = month_abbr
else:
try:
if len(set(standalone_month_name)) != len(set(month_name)):
standalone_month_name = month_name
if len(set(standalone_month_abbr)) != len(set(month_abbr)):
standalone_month_abbr = month_abbr
except ValueError:
standalone_month_name = month_name
standalone_month_abbr = month_abbr

Impact:

This breaks Python 3.15 compatibility with Wine, affecting users who build
Windows executables using PyInstaller under Wine (a common CI/CD pattern).

Related:

Linked PRs
  • gh-155269
  • gh-155317

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Lib/calendar.py の 143-156 行付近から始め、Wine 上で import calendar を再現し、独立した月シーケンス内の遅延 strftime 呼び出しに焦点を当てます。%OB/%Ob の未サポート形式によってインポートが妨げられなくなり、通常の month_name/month_abbr 値がフォールバックとして使用されれば完了です。リンクされた PR gh-155269 と gh-155317 は、この作業がすでに進行中であることを示しています。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。