From: Nicholas Tindle Date: Thu, 18 Sep 2025 16:32:14 +0000 (-0500) Subject: gh-137976: Explicitly exclude `localtime` from `available_timezones` (#138012) X-Git-Tag: v3.15.0a1~265 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0f27e102049bb5d85c744e9078ddb72fb8483446;p=thirdparty%2FPython%2Fcpython.git gh-137976: Explicitly exclude `localtime` from `available_timezones` (#138012) * 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> --- diff --git a/Doc/library/zoneinfo.rst b/Doc/library/zoneinfo.rst index 53d8e2598ec1..fe7d57690fad 100644 --- a/Doc/library/zoneinfo.rst +++ b/Doc/library/zoneinfo.rst @@ -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:: diff --git a/Lib/test/test_zoneinfo/test_zoneinfo.py b/Lib/test/test_zoneinfo/test_zoneinfo.py index 2f9a5dfc1a89..49b620f5c8af 100644 --- a/Lib/test/test_zoneinfo/test_zoneinfo.py +++ b/Lib/test/test_zoneinfo/test_zoneinfo.py @@ -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 diff --git a/Lib/zoneinfo/_tzpath.py b/Lib/zoneinfo/_tzpath.py index 177d32c35eff..3661c837daa0 100644 --- a/Lib/zoneinfo/_tzpath.py +++ b/Lib/zoneinfo/_tzpath.py @@ -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 index 000000000000..fb19aa140bb6 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-08-21-01-46-39.gh-issue-137976.p4sb4x.rst @@ -0,0 +1 @@ +Removed ``localtime`` from the list of reported system timezones.