]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Fix unbound `exc` in babel.dates (#959)
authorAarni Koskela <akx@iki.fi>
Wed, 25 Jan 2023 19:44:22 +0000 (21:44 +0200)
committerGitHub <noreply@github.com>
Wed, 25 Jan 2023 19:44:22 +0000 (19:44 +0000)
See https://stackoverflow.com/a/24271786/51685

babel/dates.py

index 83ce728621762c68c5f4fec62290f4aae0d25d67..e1e581a30cf0cdbab4aa78d9cbf3a17d42b5699c 100644 (file)
@@ -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