Skip to content

Commit a87422f

Browse files
authored
Fix unbound exc in babel.dates (#959)
See https://stackoverflow.com/a/24271786/51685
1 parent 50e1857 commit a87422f

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

babel/dates.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,18 +239,17 @@ def get_timezone(zone: str | datetime.tzinfo | None = None) -> datetime.tzinfo:
239239
if not isinstance(zone, str):
240240
return zone
241241

242-
exc = None
243242
if pytz:
244243
try:
245244
return pytz.timezone(zone)
246-
except pytz.UnknownTimeZoneError as exc: # noqa: F841
247-
pass
245+
except pytz.UnknownTimeZoneError as e:
246+
exc = e
248247
else:
249248
assert zoneinfo
250249
try:
251250
return zoneinfo.ZoneInfo(zone)
252-
except zoneinfo.ZoneInfoNotFoundError as exc: # noqa: F841
253-
pass
251+
except zoneinfo.ZoneInfoNotFoundError as e:
252+
exc = e
254253

255254
raise LookupError(f"Unknown timezone {zone}") from exc
256255

0 commit comments

Comments
 (0)