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