feat: Add codec accessors from (Async)Array; remove codec subclasses#44
Conversation
|
A consequence of this simplification (of not exposing subclasses) is that we have worse type hinting, because we can't type both the strict codec metadata from We could improve type hinting if we brought back subclasses, but I'm not sure if type hinting is worth bringing back the more complex subclass approach. cc @d-v-b Claude:Codec Python API: how to type known vs. unknown (plugin) codecsContext
We currently have a lean design: one class per category, with GoalWhen a user inspects a codec read back from an array, ideally:
Finding: a single generic class can't satisfy all three (verified with pyright)We explored making the category class generic on the discriminant, e.g. It half-works. The blocker is that the open-world fallback member has
So with a single discriminated-union class it's a trilemma — pick two. The subclass approach escapes the trilemmaConcrete subclasses + nominal ( class BytesToBytesCodec: # base / open-world fallback
@property
def config(self) -> Mapping[str, object] | None: ...
class Gzip(BytesToBytesCodec):
@property
def config(self) -> GzipCodecConfiguration: ... |
Change list
codecsaccessor returning an array of codecs,Array/AsyncArraynow returncompressors(BytesToBytes codecs),filters(ArrayToArray codecs) andserializer(ArrayToBytes codec) as three different properties. This matches upstream Zarr-Python.Bloscas a class, it's now just a function to create aBytesToBytesCodecclass. This is simpler code and it also makes it simpler to return codecs, because we don't have to downcast to a specific Python subclass. We can returnBytesToBytesCodecclasses generically.name,config,andfrom_configmethods to each codec type.CodecChain, as it's now superseded by the specific codec types returned from Array/AsyncArray