Rework and enhance type hierarchy and generics #115
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context: single-cell-data/TileDB-SOMA#638 and single-cell-data/TileDB-SOMA#540
BaseCollection
, allowingCollection
to add the semantics of "no semantics". This mirrors the implementation intiledbsoma
.Measurement
andExperiment
inherit fromBaseCollection
. Previous problems with this were due to missing__slots__
.Measurement
andExperiment
that allow implementations to specify the exact types they provide, saving a lot ofcast
ing down the road.add_new_collection
for better type inference._Experimentish
to only expect read accessors, not writers.While these new changes add a bunch of generic slots to the base collection types and experiments and measurements, the experience from the perspective of a SOMA library user will be roughly the same. That is to say, it's a little scary here, but the end user will still see
theimpl.Collection[ElementType]
. Type inference when using composed objects is better as well:There is no change at runtime; the actual types of the objects remain the same, but autocompletion, type checking, and other tooling has a much better idea of what is going on.
To show what this looks like on the
tiledbsoma
side, the diff is pretty small, but the key part is in io.py, where thecast(tiledbsoma.Measurement, ms[whatever])
no longer needs to happen, since the type system already knows it’s atiledbsoma.Measurement
. While that is the only change there specifically, there will be corresponding improvements in user code.And just to reiterate: runtime behavior is identical, and any code which works now will continue to work, but static type inference is significantly improved.