We want to be able to specify "any kind of float" or "any kind of int." Currently these are implemented by a tuple of types, bridging from nptyping's version, but they should actually be unions.
We could just implement support for Unions directly and make convenience unions in the dtype module. initially this wasn't done to avoid introducing the complexity that comes with handling the full python typing API (eg. what would it mean to do NDArray[Any, tuple[int, float]] ) but it's pretty clear that Unions at least should be supported.
We could make a type that wraps multiple types, but that would introduce more complexity down the line when we move to a proper ProtocolGeneric for NDArray and want to make type hints work, so I think Union support is the way to go here.
From: https://github.com/LiberTEM/LiberTEM-schema/pull/7
We want to be able to specify "any kind of float" or "any kind of int." Currently these are implemented by a tuple of types, bridging from nptyping's version, but they should actually be unions.
We could just implement support for
Union
s directly and make convenience unions in thedtype
module. initially this wasn't done to avoid introducing the complexity that comes with handling the full python typing API (eg. what would it mean to doNDArray[Any, tuple[int, float]]
) but it's pretty clear that Unions at least should be supported.We could make a type that wraps multiple types, but that would introduce more complexity down the line when we move to a proper
Protocol
Generic
forNDArray
and want to make type hints work, so I thinkUnion
support is the way to go here.