From 7b85eccc0c5ded9494d18bac6d2dad08ac14e441 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Sun, 15 Nov 2026 07:33:19 +0000 Subject: [PATCH] [mypyc] Preserve the debug ABI flag in extension suffixes When changing the target Python version, keep the debug flag from the host extension suffix. Cover both adding and removing the free-threaded flag on a debug build. --- mypyc/options.py | 2 +- mypyc/test/test_target_python.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mypyc/options.py b/mypyc/options.py index a116c549cbf62..9b092859ffef7 100644 --- a/mypyc/options.py +++ b/mypyc/options.py @@ -96,7 +96,7 @@ def __repr__(self) -> str: def replace_ext_suffix_version(suffix: str, version: tuple[int, int], free_threaded: bool) -> str: """Replace the Python version tag in an extension suffix such as ".cp313-win_amd64.pyd".""" tag = f"{version[0]}{version[1]}{'t' if free_threaded else ''}" - result, n = re.subn(r"(\.cpython-|\.cp)\d+t?(?=-)", rf"\g<1>{tag}", suffix, count=1) + result, n = re.subn(r"(\.cpython-|\.cp)\d+t?(?=d?-)", rf"\g<1>{tag}", suffix, count=1) if n == 0: raise ValueError( f'Can\'t target Python {version[0]}.{version[1]}{"t" if free_threaded else ""}: ' diff --git a/mypyc/test/test_target_python.py b/mypyc/test/test_target_python.py index 1ac87d0ef77cb..77e7767a5e237 100644 --- a/mypyc/test/test_target_python.py +++ b/mypyc/test/test_target_python.py @@ -40,6 +40,8 @@ def test_ext_suffix(self) -> None: for host, target, expected in [ (".cpython-313-x86_64-linux-gnu.so", "3.14t", ".cpython-314t-x86_64-linux-gnu.so"), (".cpython-314t-darwin.so", "3.13", ".cpython-313-darwin.so"), + (".cpython-312d-x86_64-linux-gnu.so", "3.14t", ".cpython-314td-x86_64-linux-gnu.so"), + (".cpython-314td-darwin.so", "3.12", ".cpython-312d-darwin.so"), (".cp313-win_amd64.pyd", "3.14t", ".cp314t-win_amd64.pyd"), ("_d.cp313t-win_amd64.pyd", "3.12", "_d.cp312-win_amd64.pyd"), ]: