Cleanup typing: use NestedSequence protocol
havogt opened this issue · 0 comments
havogt commented
Usually we express nested sequences of a concrete leave type with something like tuple[int | tuple, ...]
meaning arbitrary nesting of tuples with all leave elements being int
s. Try the following Protocol in our code base for this pattern:
class NestedSequence(Protocol[_T_co]):
def __getitem__(self, key: int, /) -> Union[_T_co, NestedSequence[_T_co]]:
...
def __len__(self, /) -> int:
...
found in https://github.com/data-apis/array-api/blob/5a145340fbe17b23aee4c7f2e5d753c64a454443/src/array_api_stubs/_2022_12/_types.py#L59 or https://github.com/numpy/numpy/blob/0be4154648cd6e90aae32246349085f7ca8f2b13/numpy/_typing/_nested_sequence.py#L19