From bd7a0861edbe7b610288b44058fbdecff1819f57 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Sun, 16 Mar 2025 17:35:10 +0000 Subject: [PATCH 1/5] Catch IsADirectoryError --- Lib/test/test_zoneinfo/test_zoneinfo.py | 1 + Lib/zoneinfo/_common.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_zoneinfo/test_zoneinfo.py b/Lib/test/test_zoneinfo/test_zoneinfo.py index 8414721555731e..12d22b9a41f581 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 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}") From 8b33e0c0a5b390286db0ab3a24fc717141f11752 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Sun, 16 Mar 2025 17:44:53 +0000 Subject: [PATCH 2/5] Commiting NEWS would be handy --- .../next/Library/2025-03-16-17-40-00.gh-issue-85702.qudq12.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-03-16-17-40-00.gh-issue-85702.qudq12.rst 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..d984371c52de76 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-03-16-17-40-00.gh-issue-85702.qudq12.rst @@ -0,0 +1,2 @@ +If :func:`zoneinfo.load_tzdata` is given a package without a resource a :exc:`ZoneInfoNotFoundError` +is raised rather than a :exc:`IsADirectoryError`. From d4ad1e1ae8fc5bef944de864aca7cf8abca0dcac Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Sun, 16 Mar 2025 17:50:56 +0000 Subject: [PATCH 3/5] Fix NEWS links --- .../Library/2025-03-16-17-40-00.gh-issue-85702.qudq12.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index d984371c52de76..b8a303a69ba021 100644 --- 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 @@ -1,2 +1,2 @@ -If :func:`zoneinfo.load_tzdata` is given a package without a resource a :exc:`ZoneInfoNotFoundError` -is raised rather than a :exc:`IsADirectoryError`. +If :func:`zoneinfo._common.load_tzdata` is given a package without a resource a +``ZoneInfoNotFoundError`` is raised rather than a :exc:`IsADirectoryError`. From 89d0845bcb0530fa86331f46136bdee1c7d64d5d Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Mon, 17 Mar 2025 09:36:43 +0000 Subject: [PATCH 4/5] Fix NEWS (again) --- .../next/Library/2025-03-16-17-40-00.gh-issue-85702.qudq12.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index b8a303a69ba021..25b549d5f0832b 100644 --- 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 @@ -1,2 +1,2 @@ -If :func:`zoneinfo._common.load_tzdata` is given a package without a resource a +If ``zoneinfo._common.load_tzdata`` is given a package without a resource a ``ZoneInfoNotFoundError`` is raised rather than a :exc:`IsADirectoryError`. From 99731e809617fe4c61e650ba41aa7cc34be4e4e7 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Date: Mon, 17 Mar 2025 16:56:35 +0000 Subject: [PATCH 5/5] Update Lib/test/test_zoneinfo/test_zoneinfo.py Co-authored-by: Victor Stinner --- Lib/test/test_zoneinfo/test_zoneinfo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_zoneinfo/test_zoneinfo.py b/Lib/test/test_zoneinfo/test_zoneinfo.py index 12d22b9a41f581..102a487b4cfa4f 100644 --- a/Lib/test/test_zoneinfo/test_zoneinfo.py +++ b/Lib/test/test_zoneinfo/test_zoneinfo.py @@ -222,7 +222,7 @@ def test_bad_keys(self): "America.Los_Angeles", "🇨🇦", # Non-ascii "America/New\ud800York", # Contains surrogate character - "Europe" # Is a directory, see issue 85702 + "Europe", # Is a directory, see issue gh-85702 ] for bad_key in bad_keys: