]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-85702: Catch IsADirectoryError in zoneinfo (#131333)
authorStan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Mon, 14 Apr 2025 17:07:51 +0000 (18:07 +0100)
committerGitHub <noreply@github.com>
Mon, 14 Apr 2025 17:07:51 +0000 (17:07 +0000)
Co-authored-by: Victor Stinner <vstinner@python.org>
Lib/test/test_zoneinfo/test_zoneinfo.py
Lib/zoneinfo/_common.py
Misc/NEWS.d/next/Library/2025-03-16-17-40-00.gh-issue-85702.qudq12.rst [new file with mode: 0644]

index 8414721555731ebbbb593e3f6a49c3f66e05fc1f..102a487b4cfa4f5a9093f8776e27ada852ff6117 100644 (file)
@@ -222,6 +222,7 @@ class ZoneInfoTest(TzPathUserMixin, ZoneInfoTestBase):
             "America.Los_Angeles",
             "🇨🇦",  # Non-ascii
             "America/New\ud800York",  # Contains surrogate character
+            "Europe",  # Is a directory, see issue gh-85702
         ]
 
         for bad_key in bad_keys:
index 98cdfe37ca6caef972d20bf15fce8f664adbad6a..6e05abc32394bca962ae5ead89182acd3d24b6e2 100644 (file)
@@ -10,7 +10,7 @@ def load_tzdata(key):
 
     try:
         return resources.files(package_name).joinpath(resource_name).open("rb")
-    except (ImportError, FileNotFoundError, UnicodeEncodeError):
+    except (ImportError, FileNotFoundError, UnicodeEncodeError, IsADirectoryError):
         # There are three types of exception that can be raised that all amount
         # to "we cannot find this key":
         #
@@ -21,6 +21,7 @@ def load_tzdata(key):
         #   (e.g. Europe/Krasnoy)
         # UnicodeEncodeError: If package_name or resource_name are not UTF-8,
         #   such as keys containing a surrogate character.
+        # IsADirectoryError: If package_name without a resource_name specified.
         raise ZoneInfoNotFoundError(f"No time zone found with key {key}")
 
 
diff --git a/Misc/NEWS.d/next/Library/2025-03-16-17-40-00.gh-issue-85702.qudq12.rst b/Misc/NEWS.d/next/Library/2025-03-16-17-40-00.gh-issue-85702.qudq12.rst
new file mode 100644 (file)
index 0000000..25b549d
--- /dev/null
@@ -0,0 +1,2 @@
+If ``zoneinfo._common.load_tzdata`` is given a package without a resource a
+``ZoneInfoNotFoundError`` is raised rather than a :exc:`IsADirectoryError`.