python / python/cpython

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

Aperta
#155,245 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

OS-unsupported stdlib type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in Lib/calendar.py intorno alle righe 143-156 e riproduci import calendar sotto Wine, concentrandoti sulle chiamate lazy a strftime nelle sequenze di mesi autonome. Il lavoro sarà completato quando i formati %OB/%Ob non supportati non impediranno più l'importazione e i valori regolari month_name/month_abbr verranno usati come fallback; le PR collegate gh-155269 e gh-155317 indicano che questo lavoro è già in corso.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.