From a97c770c4033bd80127e27165891cbaad6a830a6 Mon Sep 17 00:00:00 2001 From: Dane Parin Date: Sun, 22 Nov 2026 18:40:31 +0700 Subject: [PATCH] gh-86705: Accept sys.version without compiler identification --- Lib/platform.py | 4 +++- Lib/test/test_platform.py | 6 ++++++ .../Library/2026-11-22-15-47-50.gh-issue-86705.q3Xk9L.rst | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2026-11-22-15-47-50.gh-issue-86705.q3Xk9L.rst diff --git a/Lib/platform.py b/Lib/platform.py index c87bf2fca37e03..8ff7596a1f8da1 100644 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -1167,7 +1167,7 @@ def _sys_version(sys_version=None): r'\(#?([^,]+)' # "(#buildno" r'(?:,\s*([\w ]*)' # ", builddate" r'(?:,\s*([\w :]*))?)?\)\s*' # ", buildtime)" - r'\[([^\]]+)\]?', re.ASCII) # "[compiler]" + r'(?:\[([^\]]+)\])?', re.ASCII) # "[compiler]" match = cpython_sys_version_parser.match(sys_version) if match is None: raise ValueError( @@ -1180,6 +1180,8 @@ def _sys_version(sys_version=None): builddate = '' elif buildtime: builddate = builddate + ' ' + buildtime + if compiler is None: + compiler = '' if hasattr(sys, '_git'): _, branch, revision = sys._git diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py index cf3ca9021eea3f..7d8b68d5ff2545 100644 --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -222,6 +222,12 @@ def test_sys_version(self): ('CPython', '3.10.8', '', '', ('tags/v3.10.8:aaaf517424', 'Feb 14 2023 16:28:12'), 'GCC 9.4.0'), + ("3.15.0 (main, Nov 22 2026, 15:47:50) ", + None, "linux") + : + ('CPython', '3.15.0', '', '', + ('main', 'Nov 22 2026 15:47:50'), ''), + ("2.5 (trunk:6107, Mar 26 2009, 13:02:18) \n[Java HotSpot(TM) Client VM (\"Apple Computer, Inc.\")]", ('Jython', 'trunk', '6107'), "java1.5.0_16") : diff --git a/Misc/NEWS.d/next/Library/2026-11-22-15-47-50.gh-issue-86705.q3Xk9L.rst b/Misc/NEWS.d/next/Library/2026-11-22-15-47-50.gh-issue-86705.q3Xk9L.rst new file mode 100644 index 00000000000000..e7fb1fe301502b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-11-22-15-47-50.gh-issue-86705.q3Xk9L.rst @@ -0,0 +1,2 @@ +Fix :mod:`platform` to accept :data:`sys.version` strings without compiler +identification, returning an empty string from :func:`platform.python_compiler`.