Fix parse_type_hint for numpy 2.5
Closes #769 (closed)
numpy 2.5 changed numpy.typing.NDArray from a plain TypeVar-parametrized alias into a PEP 695 TypeAliasType. The introspected structure changed:
| numpy ≤ 2.4 | numpy ≥ 2.5 | |
|---|---|---|
| NDArray[np.bool] | numpy.ndarray[Any, numpy.dtype[numpy.bool]] | NDArray[numpy.bool] (types.GenericAlias over a TypeAliasType) |
| typing.get_origin(...) | numpy.ndarray | numpy.typing.NDArray |
| typing.get_args(...) | (Any, numpy.dtype[np.bool]) | (numpy.bool,) |
PyTango's parser at tango/utils.py:619-620 relies on the old shape:
if typing.get_origin(dtype) == np.ndarray:
dtype = typing.get_args(typing.get_args(dtype)[1])[0]On 2.5 get_origin is no longer np.ndarray, so the branch is skipped entirely; the raw NDArray[...] alias falls through to TO_TANGO_TYPE[dtype] (line 511) → KeyError → the "Cannot translate" error
Fix:
Replace the single-origin check with a dual-path extractor. The scalar type is extracted differently per numpy layout, then the existing SPECTRUM/(dtype,) handling is unchanged.
Edited by Yury Matveev