Skip to content

Commit

Permalink
fix: ValueCodec as generic class
Browse files Browse the repository at this point in the history
  • Loading branch information
thorwhalen committed Nov 17, 2023
1 parent 7773e98 commit 182ef2c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions dol/kv_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def is_value_codec(attr_val):

# Note: Note clear if escaping or unescaping is the encoder or decoder here
# I have never had the need for stores using it, so will omit for now
# html: Codec[str, str] = value_wrap(html.unescape, html.escape)
# html: ValueCodec[str, str] = value_wrap(html.unescape, html.escape)

# Compression
zipfile: ValueCodec[bytes, bytes] = value_wrap(zip_compress, zip_decompress)
Expand All @@ -284,7 +284,7 @@ def is_value_codec(attr_val):
)

# Any is really xml.etree.ElementTree.Element, but didn't want to import
xml_etree: ValueCodec[Any, bytes] = value_wrap(_xml_tree_encode, _xml_tree_decode)
xml_etree: Codec[Any, bytes] = value_wrap(_xml_tree_encode, _xml_tree_decode)


from dol.paths import KeyTemplate
Expand Down
6 changes: 3 additions & 3 deletions dol/trans.py
Original file line number Diff line number Diff line change
Expand Up @@ -3028,11 +3028,11 @@ def __add__(self, other):
)


class ValueCodec(Codec):
class ValueCodec(Generic[DecodedType, EncodedType], Codec[DecodedType, EncodedType]):
def __call__(self, obj):
return wrap_kvs(obj, data_of_obj=self.encoder, obj_of_data=self.decoder)


class KeyCodec(Codec):
class KeyCodec(Generic[DecodedType, EncodedType], Codec[DecodedType, EncodedType]):
def __call__(self, obj):
return wrap_kvs(obj, id_of_key=self.encoder, key_of_id=self.decoder)
return wrap_kvs(obj, id_of_key=self.encoder, key_of_id=self.decoder)

0 comments on commit 182ef2c

Please sign in to comment.