https://github.com/python/cpython/commit/4f4fa726956bc8f0c1f3a4c81f8d99b5472a14ff
commit: 4f4fa726956bc8f0c1f3a4c81f8d99b5472a14ff
branch: 3.13
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: vstinner <vstin...@python.org>
date: 2025-06-30T15:00:56Z
summary:

[3.13] gh-85702: Catch IsADirectoryError in zoneinfo (GH-131333) (#136130)

gh-85702: Catch IsADirectoryError in zoneinfo (GH-131333)
(cherry picked from commit d22604a6d1237c42ec5f43df51dfa9aa58240ba4)

Co-authored-by: Stan Ulbrych <89152624+stanfromirel...@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstin...@python.org>

files:
A Misc/NEWS.d/next/Library/2025-03-16-17-40-00.gh-issue-85702.qudq12.rst
M Lib/test/test_zoneinfo/test_zoneinfo.py
M Lib/zoneinfo/_common.py

diff --git a/Lib/test/test_zoneinfo/test_zoneinfo.py 
b/Lib/test/test_zoneinfo/test_zoneinfo.py
index 8bcd6d2e9951b9..f687f29c2224ea 100644
--- a/Lib/test/test_zoneinfo/test_zoneinfo.py
+++ b/Lib/test/test_zoneinfo/test_zoneinfo.py
@@ -222,6 +222,7 @@ def test_bad_keys(self):
             "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:
diff --git a/Lib/zoneinfo/_common.py b/Lib/zoneinfo/_common.py
index 98cdfe37ca6cae..6e05abc32394bc 100644
--- a/Lib/zoneinfo/_common.py
+++ b/Lib/zoneinfo/_common.py
@@ -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
index 00000000000000..25b549d5f0832b
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-03-16-17-40-00.gh-issue-85702.qudq12.rst
@@ -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`.

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to