]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-137976: Explicitly exclude `localtime` from `available_timezones` (#138012)
authorNicholas Tindle <nicktindle@outlook.com>
Thu, 18 Sep 2025 16:32:14 +0000 (11:32 -0500)
committerGitHub <noreply@github.com>
Thu, 18 Sep 2025 16:32:14 +0000 (17:32 +0100)
* fix: available_timezones is reporting an invalid IANA zone name

* ðŸ“œðŸ¤– Added by blurb_it.

* correct rst format for backticks

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
Doc/library/zoneinfo.rst
Lib/test/test_zoneinfo/test_zoneinfo.py
Lib/zoneinfo/_tzpath.py
Misc/NEWS.d/next/Core_and_Builtins/2025-08-21-01-46-39.gh-issue-137976.p4sb4x.rst [new file with mode: 0644]

index 53d8e2598ec1c783804381acbbd56c67e3ab0498..fe7d57690fad5c157d2ccadf1301569b9d2cc917 100644 (file)
@@ -349,7 +349,7 @@ Functions
 
     This function only includes canonical zone names and does not include
     "special" zones such as those under the ``posix/`` and ``right/``
-    directories, or the ``posixrules`` zone.
+    directories, the ``posixrules``  or the ``localtime`` zone.
 
     .. caution::
 
index 2f9a5dfc1a89a0eecf485359e0cfbe09aede7a13..49b620f5c8af16456a982f3dd1ac1f3d69c8df21 100644 (file)
@@ -1951,6 +1951,21 @@ class TestModule(ZoneInfoTestBase):
                 actual = self.module.available_timezones()
                 self.assertEqual(actual, expected)
 
+    def test_exclude_localtime(self):
+        expected = {
+            "America/New_York",
+            "Europe/London",
+        }
+
+        tree = list(expected) + ["localtime"]
+
+        with tempfile.TemporaryDirectory() as td:
+            for key in tree:
+                self.touch_zone(key, td)
+
+            with self.tzpath_context([td]):
+                actual = self.module.available_timezones()
+                self.assertEqual(actual, expected)
 
 class CTestModule(TestModule):
     module = c_zoneinfo
index 177d32c35eff29625c2edaea6489a3e45641c77f..3661c837daa0a416f986b8f278421c2dec3c3010 100644 (file)
@@ -177,6 +177,10 @@ def available_timezones():
         # posixrules is a special symlink-only time zone where it exists, it
         # should not be included in the output
         valid_zones.remove("posixrules")
+    if "localtime" in valid_zones:
+        # localtime is a special symlink-only time zone where it exists, it
+        # should not be included in the output
+        valid_zones.remove("localtime")
 
     return valid_zones
 
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-08-21-01-46-39.gh-issue-137976.p4sb4x.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-08-21-01-46-39.gh-issue-137976.p4sb4x.rst
new file mode 100644 (file)
index 0000000..fb19aa1
--- /dev/null
@@ -0,0 +1 @@
+Removed ``localtime`` from the list of reported system timezones.