-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework and enhance type hierarchy and generics. (#115)
- Pulls basic collection impl into BaseCollection, allowing Collection to add the semantics of "no semantics". This mirrors the implementation in tiledbsoma. - Makes Measurement and Experiment inherit from BaseCollection. Previous problems with this were due to missing `__slots__`. - Adds generic parameters to Measurement and Experiment that allow implementations to specify the exact types they provide, saving a lot of `cast`ing down the road. - Renames lots of TypeVars to be clearer about their purpose. - Adds overloads to `add_new_collection` for better type inference. - Tightens `_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: some_exp = theimpl.Experiment.open(...) obs = some_exp.obs reveal_type(obs) # BEFORE: somacore.DataFrame # (i.e., the type system doesn't know what implementation # of the abstract DataFrame this is; it only knows about # the bare minimum DataFrame properties) # AFTER: theimpl.DataFrame ms = some_exp.ms reveal_type(ms) # BEFORE: somacore.Collection[somacore.Measurement] # AFTER: theimpl.Collection[theimpl.Measurement] some_meas = ms["whatever"] reveal_type(ms) # BEFORE: somacore.Measurement # AFTER: theimpl.Measurement some_meas.X reveal_type(ms) # BEFORE: somacore.Collection[somacore.NDArray] # AFTER: theimpl.Collection[theimpl.NDArray] 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.
- Loading branch information
1 parent
81f4eb4
commit 4aab19f
Showing
5 changed files
with
166 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.