From aada86660013859510eadef4c5d2b31f93f4581a Mon Sep 17 00:00:00 2001 From: Jonathan Dung Date: Sat, 28 Mar 2026 11:38:13 +0800 Subject: [PATCH 1/2] Raise SystemError instead of plain Exception in case of internal version inconsistency --- Lib/ctypes/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py index 7223fc499773aa..41819680744c42 100644 --- a/Lib/ctypes/__init__.py +++ b/Lib/ctypes/__init__.py @@ -19,7 +19,7 @@ from struct import calcsize as _calcsize if __version__ != _ctypes_version: - raise Exception("Version number mismatch", __version__, _ctypes_version) + raise SystemError("Version number mismatch", __version__, _ctypes_version) if _os.name == "nt": from _ctypes import COMError, CopyComPointer, FormatError From b274a2bfd58df84bf687e13bf66854561550539b Mon Sep 17 00:00:00 2001 From: Jonathan Dung Date: Sat, 28 Mar 2026 13:35:58 +0800 Subject: [PATCH 2/2] Incorporate suggestion by @Shrey-N Co-authored-by: Shrey Naithani --- Lib/ctypes/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py index 41819680744c42..a4f86d2f97d937 100644 --- a/Lib/ctypes/__init__.py +++ b/Lib/ctypes/__init__.py @@ -19,7 +19,9 @@ from struct import calcsize as _calcsize if __version__ != _ctypes_version: - raise SystemError("Version number mismatch", __version__, _ctypes_version) + raise SystemError( + f"ctypes version mismatch: Python={__version__}, _ctypes={_ctypes_version}" +) if _os.name == "nt": from _ctypes import COMError, CopyComPointer, FormatError