Skip to content

Use a gradual shape-type for the AudioData type alias#490

Open
jorenham wants to merge 1 commit into
bastibe:masterfrom
jorenham:typing/gradual-AudioData-shape
Open

Use a gradual shape-type for the AudioData type alias#490
jorenham wants to merge 1 commit into
bastibe:masterfrom
jorenham:typing/gradual-AudioData-shape

Conversation

@jorenham

Copy link
Copy Markdown

I noticed that you're using shape-typing for numpy ndarray types; awesome!

One thing that could help avoid some annoying typing errors, is to use tuple[Any, ...] instead of tupleint, ...] to represent an unknown shape type. That's because tuple[int, ...] is only assignable to tuple[int, ...] and not to e.g. tuple[int]. That's why there's tuple[Any, ...], which doesn't have this issue; it's assignable to tuple types of any length. So with this "gradual" shape-type, users no longer have to explicitly cast it to the "actual" shape type in their code (or # type: ignore it).

FWIW; recent versions of numpy (>=2.1) also use tuple[Any, ...] as shape-type of numpy.typing.NDArray for this reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant