type hinting tuples of fixed but rather large fixed length
Question:
I currently type hint a function returning tuple as follows:
FuncOutput = Tuple[nib.Nifti1Image,
nib.Nifti1Image,
nib.Nifti1Image,
nib.Nifti1Image,
nib.Nifti1Image,
nib.Nifti1Image,
nib.Nifti1Image]
Is there a way to do this in a concise manner where I can specify the length without typing it so many times?
Answers:
No. typing.Tuple
only supports typing each element or a variable number of elements.
You can use type variable.
T = TypeVar('T')
tuple7 = tuple[T, T, T, T, T, T, T]
# then you can write
FuncOutput = tuple7[nib.Nifti1Image]
I currently type hint a function returning tuple as follows:
FuncOutput = Tuple[nib.Nifti1Image,
nib.Nifti1Image,
nib.Nifti1Image,
nib.Nifti1Image,
nib.Nifti1Image,
nib.Nifti1Image,
nib.Nifti1Image]
Is there a way to do this in a concise manner where I can specify the length without typing it so many times?
No. typing.Tuple
only supports typing each element or a variable number of elements.
You can use type variable.
T = TypeVar('T')
tuple7 = tuple[T, T, T, T, T, T, T]
# then you can write
FuncOutput = tuple7[nib.Nifti1Image]