summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAarni Koskela <akx@iki.fi>2023-01-25 21:31:32 +0200
committerAarni Koskela <akx@iki.fi>2023-01-25 21:41:07 +0200
commit1a616cf81c0cdb3ed10210cca7abdadb71969f5d (patch)
tree0cd0690ff759f3d18c768103a0d402ae98e0d0ad
parent2c1875e57415974a76fbe022c16b7893576d185b (diff)
downloadbabel-unbound-exc.tar.gz
Fix unbound `exc` in babel.datesunbound-exc
See https://stackoverflow.com/a/24271786/51685
-rw-r--r--babel/dates.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/babel/dates.py b/babel/dates.py
index ce79318..f5d996e 100644
--- a/babel/dates.py
+++ b/babel/dates.py
@@ -243,18 +243,17 @@ def get_timezone(zone: str | datetime.tzinfo | None = None) -> datetime.tzinfo:
if not isinstance(zone, str):
return zone
- exc = None
if pytz:
try:
return pytz.timezone(zone)
- except pytz.UnknownTimeZoneError as exc: # noqa: F841
- pass
+ except pytz.UnknownTimeZoneError as e:
+ exc = e
else:
assert zoneinfo
try:
return zoneinfo.ZoneInfo(zone)
- except zoneinfo.ZoneInfoNotFoundError as exc: # noqa: F841
- pass
+ except zoneinfo.ZoneInfoNotFoundError as e:
+ exc = e
raise LookupError(f"Unknown timezone {zone}") from exc