single-cell-data / SOMA

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

Shorten up constant declarations with `Final`. #59

Closed thetorpedodog closed 1 year ago

thetorpedodog commented 1 year ago

Abstract properties can be fulfilled by setting an attribute on the class itself, and using Final makes the type checker yell if you try to change it.


This used to be a much fancier idea that used descriptors to do more or less the same thing, but it would also ensure that nobody would change it at runtime. (That would have looked like this: https://github.com/single-cell-data/SOMA/commit/967ff84cdf30bb82b8caec84ad46097270e6dd13.) I don’t think the additional code there is worth it, though, since Final gives us (and users) static analysis security (and if users do start monkeying around with SOMA internals, if they break it they get to keep both pieces).