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?

Asked By: Luca

||

Answers:

No. typing.Tuple only supports typing each element or a variable number of elements.

Answered By: MisterMiyagi

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]
Answered By: function2
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.