https://github.com/python/cpython/commit/0ba7be9a18e8b03af1c046d676f71be9208e06d4
commit: 0ba7be9a18e8b03af1c046d676f71be9208e06d4
branch: main
author: Chris Eibl <[email protected]>
committer: zware <[email protected]>
date: 2026-09-13T09:21:24-05:00
summary:

gh-157368: Fix clang-cl version in sys.version on Windows (GH-157369)



Co-authored-by: Stan Ulbrych <[email protected]>

files:
A Misc/NEWS.d/next/Windows/2026-09-12-18-59-21.gh-issue-157368.2DirHP.rst
M PC/pyconfig.h

diff --git 
a/Misc/NEWS.d/next/Windows/2026-09-12-18-59-21.gh-issue-157368.2DirHP.rst 
b/Misc/NEWS.d/next/Windows/2026-09-12-18-59-21.gh-issue-157368.2DirHP.rst
new file mode 100644
index 000000000000000..72e11bfe2b15384
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2026-09-12-18-59-21.gh-issue-157368.2DirHP.rst
@@ -0,0 +1,3 @@
+Fix truncated :data:`sys.version` in the case of clang-cl versions 22 or newer
+on Windows. Also fixes the Windows on Arm case, where the Microsoft
+compiler was reported instead of clang. Patch by Chris Eibl.
diff --git a/PC/pyconfig.h b/PC/pyconfig.h
index 982d4c662599a44..5b1df0fc146c39d 100644
--- a/PC/pyconfig.h
+++ b/PC/pyconfig.h
@@ -148,17 +148,24 @@ WIN32 is still required for the locale module.
 #define MS_WIN64
 #endif
 
+#ifdef __clang__
+#define _Py_CLANG_COMPILER(platform) ( \
+   "[Clang " _Py_STRINGIZE(__clang_major__) "." _Py_STRINGIZE(__clang_minor__) 
\
+   "." _Py_STRINGIZE(__clang_patchlevel__) " " platform \
+   " with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
+#endif
+
 /* set the _Py_COMPILER and support tier
  *
  * win_amd64 MSVC (x86_64-pc-windows-msvc): 1
  * win32 MSVC (i686-pc-windows-msvc): 1
  * win_arm64 MSVC (aarch64-pc-windows-msvc): 2
- * other archs and ICC: 0
+ * other archs and clang-cl/ICC: 0
  */
 #ifdef MS_WIN64
 #if defined(_M_X64) || defined(_M_AMD64)
 #if defined(__clang__)
-#define _Py_COMPILER ("[Clang " __clang_version__ "] 64 bit (AMD64) with MSC 
v." _Py_STRINGIZE(_MSC_VER) " CRT]")
+#define _Py_COMPILER _Py_CLANG_COMPILER("64 bit (AMD64)")
 #define PY_SUPPORT_TIER 0
 #elif defined(__INTEL_COMPILER)
 #define _Py_COMPILER ("[ICC v." _Py_STRINGIZE(__INTEL_COMPILER) " 64 bit 
(amd64) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")
@@ -169,8 +176,13 @@ WIN32 is still required for the locale module.
 #endif /* __clang__ */
 #define PYD_PLATFORM_TAG "win_amd64"
 #elif defined(_M_ARM64)
+#if defined(__clang__)
+#define _Py_COMPILER _Py_CLANG_COMPILER("64 bit (ARM64)")
+#define PY_SUPPORT_TIER 0
+#else
 #define _Py_COMPILER _Py_PASTE_VERSION("64 bit (ARM64)")
 #define PY_SUPPORT_TIER 2
+#endif /* __clang__ */
 #define PYD_PLATFORM_TAG "win_arm64"
 #else
 #define _Py_COMPILER _Py_PASTE_VERSION("64 bit (Unknown)")
@@ -220,7 +232,7 @@ typedef _W64 int Py_ssize_t;
 #if defined(MS_WIN32) && !defined(MS_WIN64)
 #if defined(_M_IX86)
 #if defined(__clang__)
-#define _Py_COMPILER ("[Clang " __clang_version__ "] 32 bit (Intel) with MSC 
v." _Py_STRINGIZE(_MSC_VER) " CRT]")
+#define _Py_COMPILER _Py_CLANG_COMPILER("32 bit (Intel)")
 #define PY_SUPPORT_TIER 0
 #elif defined(__INTEL_COMPILER)
 #define _Py_COMPILER ("[ICC v." _Py_STRINGIZE(__INTEL_COMPILER) " 32 bit 
(Intel) with MSC v." _Py_STRINGIZE(_MSC_VER) " CRT]")

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to