Skip to content

Commit 5cdcbd0

Browse files
committed
Freeze cbor tags as they are supposed to be hashable
1 parent da6da64 commit 5cdcbd0

File tree

3 files changed

+96
-8
lines changed

3 files changed

+96
-8
lines changed

poetry.lock

+89-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pycardano/serialization.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from frozenlist import FrozenList
56
import re
67
import typing
78
from collections import OrderedDict, UserList, defaultdict
@@ -149,10 +150,10 @@ def default_encoder(
149150
encoder: CBOREncoder, value: Union[CBORSerializable, IndefiniteList]
150151
):
151152
"""A fallback function that encodes CBORSerializable to CBOR"""
152-
assert isinstance(value, (CBORSerializable, IndefiniteList, RawCBOR)), (
153+
assert isinstance(value, (CBORSerializable, IndefiniteList, RawCBOR, FrozenList)), (
153154
f"Type of input value is not CBORSerializable, " f"got {type(value)} instead."
154155
)
155-
if isinstance(value, IndefiniteList):
156+
if isinstance(value, IndefiniteList) or isinstance(value, FrozenList):
156157
# Currently, cbor2 doesn't support indefinite list, therefore we need special
157158
# handling here to explicitly write header (b'\x9f'), each body item, and footer (b'\xff') to
158159
# the output bytestring.
@@ -253,7 +254,9 @@ def _dfs(value):
253254
elif isinstance(value, IndefiniteList):
254255
return IndefiniteList([_helper(k) for k in value])
255256
elif isinstance(value, CBORTag):
256-
return CBORTag(value.tag, _helper(value.value))
257+
value_list = FrozenList(_helper(value.value))
258+
value_list.freeze()
259+
return CBORTag(value.tag, value_list)
257260
else:
258261
return value
259262

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ cose = "0.9.dev8"
3232
pprintpp = "^0.4.0"
3333
mnemonic = "^0.20"
3434
ECPy = "^1.2.5"
35+
frozenlist = "^1.3.3"
3536

3637
[tool.poetry.dev-dependencies]
3738
Sphinx = "^4.3.2"

0 commit comments

Comments
 (0)