calendar module fails to import on Wine due to incomplete %OB error handling
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu trong Lib/calendar.py quanh các dòng 143-156 và tái hiện import calendar trên Wine, tập trung vào các lệnh gọi strftime lazy trong các chuỗi tháng độc lập. Công việc được xem là hoàn tất khi các định dạng %OB/%Ob không được hỗ trợ không còn ngăn việc import và các giá trị month_name/month_abbr thông thường được dùng làm fallback; các PR được liên kết gh-155269 và gh-155317 cho biết công việc này đã được tiến hành.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 25/100