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] Make `Slice` protocol not `runtime_checkable` #128

Closed thetorpedodog closed 1 year ago

thetorpedodog commented 1 year ago

Since range has the members start/stop/step, that meant that isinstance(range(x), Slice) would return True, when a range is not a Slice. Using abc and manually registering slice fixes this.

This also unrestricts Slices from being Comparable, since the built-in slice type does not have this restriction, and adds the is_slice_of function, taken from tiledbsoma.

thetorpedodog commented 1 year ago

Update: Since mypy doesn’t currently understand SomeABC.register(other_type), that approach Did Not Work well in reality. Instead, I’ve just removed the runtime_checkableility of the protocol and made is_slice_of the canonical type-checking method.

thetorpedodog commented 1 year ago

Oops, had not noticed the approval. Reverting to the approved state (i.e. no longer removing Comparable) and saving that for another change.