From 616eb277c3ead18e0003a54d029294ea6d1e382e Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Thu, 20 Aug 2026 08:53:58 -0500 Subject: [PATCH] COMP: Resolve Python ST/IT/OT from the wrapped C types Wrapping/WrapBasicTypes.cmake selects unsigned long long for itk::IdentifierType only when both WIN32 and ITK_USE_64BITS_IDS hold, while itk.support.types derived the alias independently. On Windows with ITK_USE_64BITS_IDS=OFF the wrapping instantiates unsigned long while itk.IT reported a 64-bit type, so itk.VectorContainer[itk.IT, ...] named an instantiation that does not exist. Export the mangled names ITKM_ST, ITKM_IT and ITKM_OT through itkConfig and look the aliases up from there, so the Python aliases and the instantiated templates come from one definition. --- .../Generators/Python/itk/support/types.py | 19 +++++++++++++++---- .../Python/itkConfig.template.in.py | 8 ++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Wrapping/Generators/Python/itk/support/types.py b/Wrapping/Generators/Python/itk/support/types.py index 9eb29cfc1b9..ebed191ab66 100644 --- a/Wrapping/Generators/Python/itk/support/types.py +++ b/Wrapping/Generators/Python/itk/support/types.py @@ -22,6 +22,8 @@ from typing import Self, TypeAlias, Union, TYPE_CHECKING import os +from itkConfig import ITK_GLOBAL_WRAPPING_TYPE_ALIASES + try: from numpy.typing import ArrayLike except ImportError: @@ -157,10 +159,19 @@ def initialize_c_types_once(cls) -> tuple[Self, ...]: int32_t = SI int64_t = SL if SL.dtype.itemsize == 8 else SLL -# Aliases for SizeValueType, IdentifierType, OffsetType -ST = uint64_t -IT = uint64_t -OT = int64_t +# Aliases for SizeValueType, IdentifierType, OffsetType, resolved from the +# C types the wrapping actually instantiated rather than re-derived here. +_c_type_by_mangled_name: dict[str, itkCType] = { + "UL": UL, + "ULL": ULL, + "SL": SL, + "SLL": SLL, +} +ST = _c_type_by_mangled_name[ITK_GLOBAL_WRAPPING_TYPE_ALIASES["ST"]] +IT = _c_type_by_mangled_name[ITK_GLOBAL_WRAPPING_TYPE_ALIASES["IT"]] +OT = _c_type_by_mangled_name[ITK_GLOBAL_WRAPPING_TYPE_ALIASES["OT"]] +del _c_type_by_mangled_name +del ITK_GLOBAL_WRAPPING_TYPE_ALIASES # Type aliases to avoid expensive import, circular references. Use with forward references. if TYPE_CHECKING: diff --git a/Wrapping/Generators/Python/itkConfig.template.in.py b/Wrapping/Generators/Python/itkConfig.template.in.py index b6cd5d98331..b5f20020612 100644 --- a/Wrapping/Generators/Python/itkConfig.template.in.py +++ b/Wrapping/Generators/Python/itkConfig.template.in.py @@ -194,6 +194,14 @@ def _normalized_path(relative_posix_path: str, message) -> str: "ITK_WRAP_PYTHON_COMPLEX_REAL": "@ITK_WRAP_PYTHON_COMPLEX_REAL@".split(";"), } +# Mangled names of the C types the wrapping instantiated for itk::SizeValueType, +# itk::IdentifierType and itk::OffsetValueType, from Wrapping/WrapBasicTypes.cmake. +ITK_GLOBAL_WRAPPING_TYPE_ALIASES: dict[str, str] = { + "ST": "@ITKM_ST@", + "IT": "@ITKM_IT@", + "OT": "@ITKM_OT@", +} + (swig_lib, swig_py, config_py, doxygen_root, path) = _initialize() del _initialize del warnings