Title: test_importlib.test_windows: vendored `get_platform()` misdetects clang-cl builds as `win32`, failing `test_tagged_suffix` · Issue #154200 · python/cpython · GitHub
Open Graph Title: test_importlib.test_windows: vendored `get_platform()` misdetects clang-cl builds as `win32`, failing `test_tagged_suffix` · Issue #154200 · python/cpython
X Title: test_importlib.test_windows: vendored `get_platform()` misdetects clang-cl builds as `win32`, failing `test_tagged_suffix` · Issue #154200 · python/cpython
Description: Bug description: test_tagged_suffix in Lib/test/test_importlib/test_windows.py fails on Windows CPython built with clang-cl (build.bat "/p:PlatformToolset=ClangCL", documented in PCbuild/readme.txt; see the reproduction note below about ...
Open Graph Description: Bug description: test_tagged_suffix in Lib/test/test_importlib/test_windows.py fails on Windows CPython built with clang-cl (build.bat "/p:PlatformToolset=ClangCL", documented in PCbuild/readme.txt...
X Description: Bug description: test_tagged_suffix in Lib/test/test_importlib/test_windows.py fails on Windows CPython built with clang-cl (build.bat "/p:PlatformToolset=ClangCL", documented in PCbuild/...
Opengraph URL: https://github.com/python/cpython/issues/154200
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"test_importlib.test_windows: vendored `get_platform()` misdetects clang-cl builds as `win32`, failing `test_tagged_suffix`","articleBody":"### Bug description:\n\n`test_tagged_suffix` in `Lib/test/test_importlib/test_windows.py` fails on Windows CPython built with clang-cl (`build.bat \"/p:PlatformToolset=ClangCL\"`, documented in PCbuild/readme.txt; see the reproduction note below about `VSCMD_ARG_TGT_ARCH`). The root cause is the same `sys.version`-truncation misdetection that gh-145410 fixed for `sysconfig.get_platform()` in March 2026 (by moving the check into the `_sysconfig.get_platform()` C accelerator, GH-146145) — but this test computes its expected suffix with a vendored \"[Port of distutils.util.get_platform()](https://github.com/python/cpython/blob/16d0c89b875c520cf5af9da5ba4db133358f742f/Lib/test/test_importlib/test_windows.py#L20-L37)\" that still carries the pre-fix logic: it sniffs `sys.version.lower()` for `'amd64'`, misses on the truncated clang banner, and falls through to `return sys.platform` → `'win32'`.\n\n```\n$ python -m unittest -v test.test_importlib.test_windows -k tagged\ntest_tagged_suffix (test.test_importlib.test_windows.Frozen_WindowsExtensionSuffixTests.test_tagged_suffix) ... FAIL\ntest_tagged_suffix (test.test_importlib.test_windows.Source_WindowsExtensionSuffixTests.test_tagged_suffix) ... FAIL\n\n======================================================================\nFAIL: test_tagged_suffix (test.test_importlib.test_windows.Frozen_WindowsExtensionSuffixTests.test_tagged_suffix)\n----------------------------------------------------------------------\nTraceback (most recent call last):\n File \"D:\\Python\\3.16t\\Lib\\test\\test_importlib\\test_windows.py\", line 154, in test_tagged_suffix\n self.assertIn(expected_tag, suffixes)\n ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^\nAssertionError: '.cp316t-win32.pyd' not found in ['.cp316t-win_amd64.pyd', '.pyd']\n```\n\n(the `Source_` variant fails identically)\n\n**Reproduction note:** the vendored function checks `VSCMD_ARG_TGT_ARCH` first, so the failure only manifests *outside* a VS developer prompt (or with a non-matching target arch); inside `vcvars64` the env var masks it and the test passes. Run the repro from a plain shell.\n\nThe interpreter itself is right — the test's expectation is wrong:\n\n```pycon\n>>> import sys, sysconfig\n>>> sys.version\n'3.16.0a0 free-threading build (heads/ft-opt-dirty:2f032556f42, Jul 16 2026, 11:20:12) [Clang 22.1.8 (https://github.com/llvm/llvm-project ca7933e47d3a3451d81e72ac174d'\n>>> sysconfig.get_platform() # fixed by gh-145410\n'win-amd64'\n>>> from test.test_importlib.test_windows import get_platform; get_platform() # vendored copy, pre-fix logic\n'win32'\n>>> import importlib.machinery; importlib.machinery.EXTENSION_SUFFIXES\n['.cp316t-win_amd64.pyd', '.pyd']\n```\n\n`EXTENSION_SUFFIXES` is built from `PYD_PLATFORM_TAG` in `PC/pyconfig.h` and is correct; only the test's vendored helper is stale.\n\n**Why the banner sniff misses on clang-cl builds:** [`PC/pyconfig.h#L161`](https://github.com/python/cpython/blob/16d0c89b875c520cf5af9da5ba4db133358f742f/PC/pyconfig.h#L161) does put `\"] 64 bit (AMD64) with MSC v.NNNN CRT]\"` into the clang compiler banner — but [`Python/getversion.c#L18-L20`](https://github.com/python/cpython/blob/16d0c89b875c520cf5af9da5ba4db133358f742f/Python/getversion.c#L18-L20) caps the compiler segment of `sys.version` at `%.80s`, and official LLVM Windows binaries have an 86-char `__clang_version__` (version + URL + full 40-char commit hash — verified against the `llvmorg-22.1.8` tag commit `ca7933e4…`). With the 7-char `\"[Clang \"` prefix the 80-char cut always lands inside the hash, so the tail carrying `(AMD64)` is truncated away — note the banner above ends 28 characters into the commit hash, inside a never-closed parenthesis, with no `(AMD64)` and no closing bracket. An MSVC banner (`[MSC v.19NN 64 bit (AMD64)]`, ~27 chars) is never truncated, which is why this is clang-specific.\n\n**Prior art:** the same assertion tripped on an early free-threaded Windows buildbot (gh-110359, 2023: `'_d.cp313-win32.pyd' not found in ['_d.cp313t-win_amd64.pyd', '_d.pyd']`). That report's `win32` came from the builder's VS target-arch environment rather than from banner truncation — an MSVC compiler segment is far too short to truncate — but it is the same expected-tag computation going wrong. Only the abi-flag half was addressed there (gh-109740; GH-110422 for gh-110119); the vendored platform sniff was left untouched, and it is what now bites clang-cl builds. Free-threading isn't part of the mechanism either — only the `abi_flags` term of the expected tag depends on it, so a non-FT clang-cl build should fail identically with `.cp316-win32.pyd` vs `.cp316-win_amd64.pyd` (I've only run free-threaded builds myself).\n\n**Suggested fix** (deferring to the maintainers): replace the [`get_platform()` call at L146](https://github.com/python/cpython/blob/16d0c89b875c520cf5af9da5ba4db133358f742f/Lib/test/test_importlib/test_windows.py#L146) with `sysconfig.get_platform()` and delete the vendored function (that call is its only consumer). This does not make the test circular: `SYSCONFIG_PLATFORM` in `Modules/_sysconfig.c` and `PYD_PLATFORM_TAG` in `PC/pyconfig.h` are independent definitions in separate files, so the test still cross-checks two separate code paths. I'm happy to submit a PR — the change is small and test-only.\n\n**Environment / build:** built from `2f032556f42` = local branch `ft-opt` merged with CPython main @ f62050d6574 (2026-07-16), per PCbuild with `build.bat -p x64 --disable-gil --pgo --tail-call-interp \"/p:PlatformToolset=ClangCL\"`, LLVM 22.1.8 official Windows release, Windows 11 x64; also reproduced on an earlier (June 2026) clang-cl build. All cited code verified unchanged on main as of 2026-07-19; permalinks sha-pinned to 16d0c89b875. My branch carries only build-system tuning (PCbuild props/vcxproj plus a zlib-ng header) and build-regenerated files (hence the `-dirty` banner); `Lib/test/test_importlib/test_windows.py`, `Python/getversion.c`, and `PC/pyconfig.h` are unmodified from upstream.\n\nclang-cl is `PY_SUPPORT_TIER 0`, but PCbuild documents the toolset and it is actively kept working (gh-77532; e.g. gh-146210 in 2026, gh-131278/gh-130090/gh-131035 in 2025) — and the failing logic is a test bug, not a platform gap.\n\nThe same 80-char banner truncation also breaks `ctypes.util.find_msvcrt()`'s `\"MSC v.\"` sniff, causing a `test_ctypes.test_errno` failure; filed separately as gh-154199.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nWindows\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-154210\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/SynaptSea","@type":"Person","name":"SynaptSea"},"datePublished":"2026-07-19T20:52:13Z","url":"https://github.com/python/cpython/issues/154200"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8eb1e01d-4c1f-2ffc-53f9-fdc2b1e9f8e5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CCB0:2C4BED:38A3C20:47F49ED:6B01F406 |
| html-safe-nonce | ac4cff11eb13f552b6c076ac944b8dfe22047fae03c31a85e4a62385fb429a19 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQ0IwOjJDNEJFRDozOEEzQzIwOjQ3RjQ5RUQ6NkIwMUY0MDYiLCJ2aXNpdG9yX2lkIjoiMTc1MTY1NzI0NjU3MDU0NzI2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 23ed27975b8c7c61312e1f59f683242b970db801c413ef8a12ab69bdae7e7eef |
| hovercard-subject-tag | issue:4924346138 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/154200/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b6652a7ecd593e544a1b271f126e26f988aa7953b0aaa466e42b20c9f90ca356/python/cpython/issues/154200 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b6652a7ecd593e544a1b271f126e26f988aa7953b0aaa466e42b20c9f90ca356/python/cpython/issues/154200 |
| og:image:alt | Bug description: test_tagged_suffix in Lib/test/test_importlib/test_windows.py fails on Windows CPython built with clang-cl (build.bat "/p:PlatformToolset=ClangCL", documented in PCbuild/readme.txt... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SynaptSea |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width