single-cell-data / SOMA

A flexible and extensible API for annotated 2D matrix data stored in multiple underlying formats.
MIT License
69 stars 9 forks source link

[python] Add `bool` to supported types and improve type specification #141

Closed thetorpedodog closed 1 year ago

thetorpedodog commented 1 year ago

This adds boolean to the supported sparse coordinate types and also improves the type definition of coordinate types to ensure that the values in each type are homogeneous:

BadCoord = Union[int, str]
BadCoords = Union[BadCoord, Sequence[BadCoord]]
# ["this", 1] is bad, but is a valid as a BadCoords value

GoodCoord = TypeVar("GoodCoord", int, str)
GoodCoords = Union[GoodCoord, Sequence[GoodCoord]]
# ["this", 1] is bad, and is *not* valid as a GoodCoords value
# ["this", "that"] is a valid as a GoodCoords value
# [1, 2] is valid as a GoodCoords value

I don’t see a bug entry for this but it was something we discussed earlier today, and in the process I realized another thing we could improve.

Context: #960