@@ -75,35 +75,37 @@ class CodecChain:
7575
7676 Constructed from an iterable of codecs and a chunk ArraySpec.
7777 Resolves each codec against the spec so that encode/decode can
78- run without re-resolving. Pure compute only -- no IO, no threading,
79- no batching.
78+ run without re-resolving.
8079 """
8180
8281 codecs : tuple [Codec , ...]
8382 chunk_spec : ArraySpec
8483
85- _aa_codecs : tuple [tuple [ArrayArrayCodec , ArraySpec ], ...] = field (
86- init = False , repr = False , compare = False
87- )
84+ _aa_codecs : tuple [ArrayArrayCodec , ...] = field (init = False , repr = False , compare = False )
85+ _aa_specs : tuple [ArraySpec , ...] = field (init = False , repr = False , compare = False )
8886 _ab_codec : ArrayBytesCodec = field (init = False , repr = False , compare = False )
8987 _ab_spec : ArraySpec = field (init = False , repr = False , compare = False )
9088 _bb_codecs : tuple [BytesBytesCodec , ...] = field (init = False , repr = False , compare = False )
89+ _bb_spec : ArraySpec = field (init = False , repr = False , compare = False )
9190 _all_sync : bool = field (init = False , repr = False , compare = False )
9291
9392 def __post_init__ (self ) -> None :
9493 aa , ab , bb = codecs_from_list (list (self .codecs ))
9594
96- aa_pairs : list [tuple [ ArrayArrayCodec , ArraySpec ] ] = []
95+ aa_specs : list [ArraySpec ] = []
9796 spec = self .chunk_spec
9897 for aa_codec in aa :
99- aa_pairs .append (( aa_codec , spec ) )
98+ aa_specs .append (spec )
10099 spec = aa_codec .resolve_metadata (spec )
101100
102- object .__setattr__ (self , "_aa_codecs" , tuple (aa_pairs ))
101+ object .__setattr__ (self , "_aa_codecs" , aa )
102+ object .__setattr__ (self , "_aa_specs" , tuple (aa_specs ))
103103 object .__setattr__ (self , "_ab_codec" , ab )
104104 object .__setattr__ (self , "_ab_spec" , spec )
105105
106+ spec = ab .resolve_metadata (spec )
106107 object .__setattr__ (self , "_bb_codecs" , bb )
108+ object .__setattr__ (self , "_bb_spec" , spec )
107109
108110 object .__setattr__ (
109111 self ,
@@ -125,11 +127,11 @@ def decode_chunk(
125127 """
126128 bb_out : Any = chunk_bytes
127129 for bb_codec in reversed (self ._bb_codecs ):
128- bb_out = cast ("SupportsSyncCodec" , bb_codec )._decode_sync (bb_out , self .chunk_spec )
130+ bb_out = cast ("SupportsSyncCodec" , bb_codec )._decode_sync (bb_out , self ._bb_spec )
129131
130132 ab_out : Any = cast ("SupportsSyncCodec" , self ._ab_codec )._decode_sync (bb_out , self ._ab_spec )
131133
132- for aa_codec , spec in reversed (self ._aa_codecs ):
134+ for aa_codec , spec in zip ( reversed (self ._aa_codecs ), reversed ( self . _aa_specs ), strict = True ):
133135 ab_out = cast ("SupportsSyncCodec" , aa_codec )._decode_sync (ab_out , spec )
134136
135137 return ab_out # type: ignore[no-any-return]
@@ -144,7 +146,7 @@ def encode_chunk(
144146 """
145147 aa_out : Any = chunk_array
146148
147- for aa_codec , spec in self ._aa_codecs :
149+ for aa_codec , spec in zip ( self ._aa_codecs , self . _aa_specs , strict = True ) :
148150 if aa_out is None :
149151 return None
150152 aa_out = cast ("SupportsSyncCodec" , aa_codec )._encode_sync (aa_out , spec )
@@ -156,7 +158,7 @@ def encode_chunk(
156158 for bb_codec in self ._bb_codecs :
157159 if bb_out is None :
158160 return None
159- bb_out = cast ("SupportsSyncCodec" , bb_codec )._encode_sync (bb_out , self .chunk_spec )
161+ bb_out = cast ("SupportsSyncCodec" , bb_codec )._encode_sync (bb_out , self ._bb_spec )
160162
161163 return bb_out # type: ignore[no-any-return]
162164
0 commit comments