typing.get_type_hints() on any wrapped filter raises TypeError under Python 3.14, so MedianImageFilterTest.py fails.
Reproduce
Python 3.14.6, ITK 6.0.0 (main), macOS arm64, ITK_WRAP_PYTHON=ON:
import itk, typing
typing.get_type_hints(itk.median_image_filter, globalns={"itk": itk})
TypeError: unsupported operand type(s) for |: 'itkTemplate' and 'typing.TypeAliasType'
The same failure occurs for itk.binary_threshold_image_filter, so it is not
specific to one filter.
Where it bites in the test suite
Modules/Filtering/Smoothing/wrapping/test/MedianImageFilterTest.py:58 calls
get_type_hints() directly, so PythonMedianImageFilterTest fails:
File ".../MedianImageFilterTest.py", line 58, in <module>
type_hints = get_type_hints(itk.median_image_filter, globalns={"itk": itk})
File ".../python3.14/typing.py", line 2441, in get_type_hints
value = _eval_type(value, globalns, localns, (), format=format, owner=obj, prefer_fwd_module=True)
File ".../python3.14/typing.py", line 490, in _eval_type
return functools.reduce(operator.or_, ev_args)
TypeError: unsupported operand type(s) for |: 'itkTemplate' and 'typing.TypeAliasType'
Cause
Python 3.14's typing._eval_type evaluates a union annotation by reducing its
arguments with operator.or_. The generated annotations mix itkTemplate
instances with typing.TypeAliasType values, and itkTemplate does not
implement __or__ / __ror__ for that operand, so the reduction raises.
Earlier Python versions did not take this path, which is why the test passes
there.
Possible directions
- Give
itkTemplate __or__ / __ror__ returning typing.Union[...], so the
reduction Python 3.14 performs succeeds.
- Or emit the annotations as
typing.Union[...] rather than X | Y, so no
runtime | is evaluated.
Happy to prepare a patch once the preferred direction is clear.
typing.get_type_hints()on any wrapped filter raisesTypeErrorunder Python 3.14, soMedianImageFilterTest.pyfails.Reproduce
Python 3.14.6, ITK 6.0.0 (main), macOS arm64,
ITK_WRAP_PYTHON=ON:The same failure occurs for
itk.binary_threshold_image_filter, so it is notspecific to one filter.
Where it bites in the test suite
Modules/Filtering/Smoothing/wrapping/test/MedianImageFilterTest.py:58callsget_type_hints()directly, soPythonMedianImageFilterTestfails:Cause
Python 3.14's
typing._eval_typeevaluates a union annotation by reducing itsarguments with
operator.or_. The generated annotations mixitkTemplateinstances with
typing.TypeAliasTypevalues, anditkTemplatedoes notimplement
__or__/__ror__for that operand, so the reduction raises.Earlier Python versions did not take this path, which is why the test passes
there.
Possible directions
itkTemplate__or__/__ror__returningtyping.Union[...], so thereduction Python 3.14 performs succeeds.
typing.Union[...]rather thanX | Y, so noruntime
|is evaluated.Happy to prepare a patch once the preferred direction is clear.