summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAarni Koskela <akx@iki.fi>2023-01-25 21:44:22 +0200
committerGitHub <noreply@github.com>2023-01-25 19:44:22 +0000
commita87422fe5e01c6292c9bd0fd35832f789872213c (patch)
treef1df70162fa6502e5f35b51c11d7902756190ba3
parent50e1857b3b4469f9dc652849bf2fa053739bcf61 (diff)
downloadbabel-a87422fe5e01c6292c9bd0fd35832f789872213c.tar.gz
Fix unbound `exc` in babel.dates (#959)
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 83ce728..e1e581a 100644
--- a/babel/dates.py
+++ b/babel/dates.py
@@ -239,18 +239,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