calendar module fails to import on Wine due to incomplete %OB error handling
还没有人认领这个 Issue。
- 主要语言
- 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:
- Run Python 3.15 under Wine (any version 9.0-11.14)
- 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:
- Original feature: https://github.com/python/cpython/issues/131146
- Wine bug (to be filed): strftime missing %O modifier support
Linked PRs
- gh-155269
- gh-155317
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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