Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup typing: use NestedSequence protocol #1394

Open
havogt opened this issue Dec 12, 2023 · 0 comments
Open

Cleanup typing: use NestedSequence protocol #1394

havogt opened this issue Dec 12, 2023 · 0 comments
Labels
triage: enhancement New feature or request

Comments

@havogt
Copy link
Contributor

havogt commented Dec 12, 2023

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 ints. 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

@havogt havogt added the triage: enhancement New feature or request label Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant