From ed8839cb9af25461c12a8d2403931ccd5c07e5e8 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 25 Jul 2024 14:28:57 +0200 Subject: [PATCH 7/9] Warn if ZoneInfo is imported without tzdata --- Lib/zoneinfo/_common.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/zoneinfo/_common.py b/Lib/zoneinfo/_common.py index 03cc42149f9..2767edb9c6a 100644 --- a/Lib/zoneinfo/_common.py +++ b/Lib/zoneinfo/_common.py @@ -15,6 +15,12 @@ def load_tzdata(key): raise IsADirectoryError return path.open("rb") except (ImportError, FileNotFoundError, UnicodeEncodeError, IsADirectoryError): + import sys + if "tzdata" not in sys.modules: + raise ZoneInfoNotFoundError( + f"No time zone found with key {key}. \n" + " On Pyodide you must do pyodide.loadPackage('tzdata')" + " package before you use zoneinfo.") # There are four types of exception that can be raised that all amount # to "we cannot find this key": # -- 2.43.0