From d63344ef8dffd59382eb98727fe0aa0d572534af Mon Sep 17 00:00:00 2001 From: Evan <36235551+SynaptSea@users.noreply.github.com> Date: Sun, 19 Jul 2026 18:17:27 -0700 Subject: [PATCH] gh-154200: Use sysconfig.get_platform() in test_importlib.test_windows test_tagged_suffix computed its expected extension suffix with a vendored port of distutils.util.get_platform() that sniffs sys.version for 'amd64'. Python/getversion.c truncates the compiler segment of sys.version at 80 characters, so on clang-cl builds -- whose banner carries a long __clang_version__ -- the marker is cut off, the helper falls through to sys.platform ('win32'), and the test expects '.cp316t-win32.pyd' while the interpreter correctly reports '.cp316t-win_amd64.pyd'. sysconfig.get_platform() no longer parses sys.version on Windows (gh-145410); it uses the _sysconfig C accelerator, which derives the platform from compile-time architecture macros and is compiler-agnostic. Use it and drop the vendored copy, its only caller. This also removes the VSCMD_ARG_TGT_ARCH branch, which trusted the ambient Visual Studio target architecture over the interpreter actually running the test. --- Lib/test/test_importlib/test_windows.py | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/Lib/test/test_importlib/test_windows.py b/Lib/test/test_importlib/test_windows.py index bef4fb46f859a4e..146a7394b2b648e 100644 --- a/Lib/test/test_importlib/test_windows.py +++ b/Lib/test/test_importlib/test_windows.py @@ -4,6 +4,7 @@ import os import re import sys +import sysconfig import unittest from test import support from test.support import import_helper @@ -17,25 +18,6 @@ EnumKey, CloseKey, DeleteKey, OpenKey ) -def get_platform(): - # Port of distutils.util.get_platform(). - TARGET_TO_PLAT = { - 'x86' : 'win32', - 'x64' : 'win-amd64', - 'arm' : 'win-arm32', - } - if ('VSCMD_ARG_TGT_ARCH' in os.environ and - os.environ['VSCMD_ARG_TGT_ARCH'] in TARGET_TO_PLAT): - return TARGET_TO_PLAT[os.environ['VSCMD_ARG_TGT_ARCH']] - elif 'amd64' in sys.version.lower(): - return 'win-amd64' - elif '(arm)' in sys.version.lower(): - return 'win-arm32' - elif '(arm64)' in sys.version.lower(): - return 'win-arm64' - else: - return sys.platform - def delete_registry_tree(root, subkey): try: hkey = OpenKey(root, subkey, access=KEY_ALL_ACCESS) @@ -143,7 +125,7 @@ def test_tagged_suffix(self): suffixes = self.machinery.EXTENSION_SUFFIXES abi_flags = "t" if support.Py_GIL_DISABLED else "" ver = sys.version_info - platform = re.sub('[^a-zA-Z0-9]', '_', get_platform()) + platform = re.sub('[^a-zA-Z0-9]', '_', sysconfig.get_platform()) expected_tag = f".cp{ver.major}{ver.minor}{abi_flags}-{platform}.pyd" try: untagged_i = suffixes.index(".pyd")