From a6a3239fad7f5fdafe840fdd2a01bdc129a9ad2a Mon Sep 17 00:00:00 2001 From: junkmd Date: Sun, 27 Jul 2025 10:17:59 +0900 Subject: [PATCH 1/2] Refactor numpy typecode generation in `_npsupport.py`. Rename from `_check_ctypeslib_typecodes` to `_build_typecodes` for clarity. --- comtypes/_npsupport.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/comtypes/_npsupport.py b/comtypes/_npsupport.py index 7e4d8276..833e78d6 100644 --- a/comtypes/_npsupport.py +++ b/comtypes/_npsupport.py @@ -92,7 +92,7 @@ def _make_variant_dtype(self): return self.numpy.dtype(tagVARIANT_format) - def _check_ctypeslib_typecodes(self): + def _build_typecodes(self): if not self.enabled: return {} import numpy as np @@ -168,7 +168,7 @@ def enable(self): # if that succeeded we can be enabled self.enabled = True self.VARIANT_dtype = self._make_variant_dtype() - self.typecodes = self._check_ctypeslib_typecodes() + self.typecodes = self._build_typecodes() self.datetime64 = self.numpy.datetime64 self.com_null_date64 = self.numpy.datetime64("1899-12-30T00:00:00", "ns") From 514f052094a08b51599bde9158ac21063c6c4c91 Mon Sep 17 00:00:00 2001 From: junkmd Date: Sun, 27 Jul 2025 10:17:59 +0900 Subject: [PATCH 2/2] Refactor numpy typecode generation in `_npsupport.py`. Remove overwriting `ctypeslib._typecodes` because `_typecodes` was removed in `numpy==1.16` (`numpy` supporting Python3.8 is `1.17` and above). --- comtypes/_npsupport.py | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/comtypes/_npsupport.py b/comtypes/_npsupport.py index 833e78d6..fa35e1ed 100644 --- a/comtypes/_npsupport.py +++ b/comtypes/_npsupport.py @@ -96,23 +96,17 @@ def _build_typecodes(self): if not self.enabled: return {} import numpy as np - from numpy import ctypeslib - - try: - from numpy.ctypeslib import _typecodes - except ImportError: - from numpy.ctypeslib import as_ctypes_type - - dtypes_to_ctypes = {} - - for tp in set(np.sctypeDict.values()): - try: - ctype_for = as_ctypes_type(tp) - dtypes_to_ctypes[np.dtype(tp).str] = ctype_for - except NotImplementedError: - continue - ctypeslib._typecodes = dtypes_to_ctypes - return ctypeslib._typecodes + from numpy.ctypeslib import as_ctypes_type + + dtypes_to_ctypes = {} + + for tp in set(np.sctypeDict.values()): + try: + ctype_for = as_ctypes_type(tp) + dtypes_to_ctypes[np.dtype(tp).str] = ctype_for + except NotImplementedError: + continue + return dtypes_to_ctypes def isndarray(self, value): """Check if a value is an ndarray.