Use a gradual shape-type for the AudioData type alias#490
Conversation
|
This is related to #484. Since you are a user of type annotations, I would love to get your input on the typing situation in general. |
|
To be honest I'm not a direct user of these annotations. I stumbled upon this while improving the annotations of librosa, which has In #484 there indeed is a similar change, where |
|
Linting rules for annotations might be of interest… https://docs.astral.sh/ruff/rules/#flake8-annotations-ann https://docs.astral.sh/ruff/rules/#numpy-specific-rules-npy % |
I noticed that you're using shape-typing for numpy
ndarraytypes; awesome!One thing that could help avoid some annoying typing errors, is to use
tuple[Any, ...]instead oftupleint, ...]to represent an unknown shape type. That's becausetuple[int, ...]is only assignable totuple[int, ...]and not to e.g.tuple[int]. That's why there'stuple[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 explicitlycastit to the "actual" shape type in their code (or# type: ignoreit).FWIW; recent versions of numpy (>=2.1) also use
tuple[Any, ...]as shape-type ofnumpy.typing.NDArrayfor this reason.