StaticTzInfo has localize() but not normalize(), so pytz-detecting code crashes on it
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 1/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 70/100
Direzione di ricerca
Inizia in dateparser/timezone_parser.py alla classe StaticTzInfo, accanto al suo metodo esistente localize(); è l'unica classe che il report nomina. Aggiungi un normalize() che restituisce il datetime convertito in questo offset, corrispondendo alle zone a offset fisso di pytz, e solleva ValueError per un datetime naive come fa lo snippet suggerito. Copri entrambi i casi nei test del parser dei fusi orari sotto tests/ ed eseguili; fatto significa che lo snippet di riproduzione non solleva più AttributeError. Nota che due pull request precedenti sono state chiuse senza essere unite, quindi controlla il thread prima di iniziare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Slightly related to #1590. When dateparser creates a pytz-lookalike TZ-object, it would probably be nice to add a .normalize() (which would be a noop for a static offset TZ), as downstream callers may expect it. Of course, moving to zoneinfo would make this issue moot. As far as I can understand, StaticTzInfo is a perfectly valid Tz-object, so it's also a perfectly valid option to just close this as "not a dateparser problem".
The details below the line are generated by Claude Opus 5.5, but I think I've summarized the issue pretty well already - so if you don't enjoy reading AI-generated text blobs, ignore the rest.
Describe the bug
For an explicit UTC offset or an abbreviation, dateparser returns a dateparser.timezone_parser.StaticTzInfo. It implements pytz's localize() but not normalize(). Libraries that detect pytz by duck typing (hasattr(tz, "localize"), as dateparser's own localize_timezone() does) then call normalize() and crash. This happened in recurring_ical_events: https://github.com/niccokunzmann/python-recurring-ical-events/issues/311
To Reproduce
import dateparser
dt = dateparser.parse("2026-11-21T05:00+01:00")
print(type(dt.tzinfo)) # <class 'dateparser.timezone_parser.StaticTzInfo'>
dt.tzinfo.localize # exists
dt.tzinfo.normalize(dt) # AttributeError: 'StaticTzInfo' object has no attribute 'normalize'
dateparser 1.5.1, Python 3.14, Arch Linux.
Suggested fix
Complete the imitation with the method pytz's own fixed-offset zones have:
def normalize(self, dt: datetime) -> datetime:
if dt.tzinfo is None:
raise ValueError("Naive time - no tzinfo set")
return dt.astimezone(self)
The alternative, returning a stdlib datetime.timezone(offset, name) for fixed offsets, avoids the pytz imitation altogether, but breaks callers relying on StaticTzInfo.localize(); that fits better with a general move away from pytz (#1590).
I can send a PR with a test for the normalize() method if wanted.
- Lingua principale
- Python
- Stelle
- 2.9k
- Fork
- 545
- Merge medio
- 2g 4h
- PR unite (30g)
- 17
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di scrapinghub/dateparser
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
scrapinghub/dateparser#1617 ·
I maintainer di solito rispondono entro 1 giorno
-
Validate on Python 3.15Forse già presa @kishan3 l’ha presa 25 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
scrapinghub/dateparser#1548 ·
I maintainer di solito rispondono entro 1 giorno
-
search_dates() raises IndexError for the zh-Hans, zh-Hant and yue localesForse già presa @abhi-0203 l’ha presa 88 giorni fa. Apertasearch_dates Status: Bug confirmed Type: Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
scrapinghub/dateparser#1372 ·
I maintainer di solito rispondono entro 1 giorno
-
Adopt sphinx-scrapy, with docs dependencies in a dependency groupForse già presa @yamilmaud l’ha presa 3 giorni fa. Aperta
Difficoltà 3/5 Mezza giornata Idoneità per principianti 25/100
scrapinghub/dateparser#1613 ·
I maintainer di solito rispondono entro 1 giorno
-
Enable branch coverage, upload test results and use Codecov OIDCForse già presa @yamilmaud l’ha presa 3 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 20/100
scrapinghub/dateparser#1611 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di scrapinghub/dateparser
Issue simili
-
[19.0] pos_sale: settling an order with a 0 down payment line crashes (reading 'reward_id') and leaves a wrong amount dueForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 79/100
developmentseed/titiler-covjson#164 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
awslabs/visual-asset-management-system#2164 ·
I maintainer di solito rispondono entro 1 giorno
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
MakazhanAlpamys/Soup#3589 ·
I maintainer di solito rispondono entro 1 giorno
-
channels status reports the wrong Enabled value for Feishu instances and default-enabled WebSocketAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
I maintainer di solito rispondono entro 1 giorno