@@ -327,7 +327,15 @@ def _identify_encoding(encoding, var_name: str, writing: bool = False) -> str:
327327 return result
328328
329329
330- class EncodedVariable (VariableWrapper ):
330+ class Mixin_Block_AutoChartostring :
331+ def set_auto_chartostring (self , onoff : bool ):
332+ # Silently allow a call to "turn it off", but not on.
333+ if onoff :
334+ msg = "auto_chartostring is not supported by Iris 'EncodedVariable' type."
335+ raise TypeError (msg )
336+
337+
338+ class EncodedVariable (VariableWrapper , Mixin_Block_AutoChartostring ):
331339 """A variable wrapper that translates variable data according to byte encodings."""
332340
333341 def __init__ (self , * args , ** kwargs ):
@@ -380,26 +388,18 @@ def __setitem__(self, keys, data):
380388 data = encoding_spec .encode_strings_as_bytearray (data )
381389 super ().__setitem__ (keys , data )
382390
383- def set_auto_chartostring (self , onoff : bool ):
384- msg = "auto_chartostring is not supported by Iris 'EncodedVariable' type."
385- raise TypeError (msg )
386-
387391
388- class EncodedGroup (GroupWrapper ):
392+ class EncodedGroup (GroupWrapper , Mixin_Block_AutoChartostring ):
389393 """A specialised GroupWrapper whose variables are EncodedVariables."""
390394
391395 VAR_WRAPPER_CLS = EncodedVariable
392396 GRP_WRAPPER_CLS : Any | None = None
393397
394- def set_auto_chartostring (self , onoff : bool ):
395- msg = "auto_chartostring is not supported by Iris 'EncodedGroup' type."
396- raise TypeError (msg )
397-
398398
399399EncodedGroup .GRP_WRAPPER_CLS = EncodedGroup
400400
401401
402- class EncodedDataset (DatasetWrapper ):
402+ class EncodedDataset (DatasetWrapper , Mixin_Block_AutoChartostring ):
403403 """A specialised DatasetWrapper.
404404
405405 Its groups are EncodedGroups and variables are EncodedVariables.
@@ -408,10 +408,6 @@ class EncodedDataset(DatasetWrapper):
408408 VAR_WRAPPER_CLS = EncodedVariable
409409 GRP_WRAPPER_CLS = EncodedGroup
410410
411- def set_auto_chartostring (self , onoff : bool ):
412- msg = "auto_chartostring is not supported by Iris 'EncodedGroup' type."
413- raise TypeError (msg )
414-
415411
416412class EncodedNetCDFDataProxy (NetCDFDataProxy ):
417413 __slots__ = NetCDFDataProxy .__slots__ + ("encoding_details" ,)
0 commit comments