Skip to content

Commit

Permalink
Fix failed tests in ^3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
cffls committed Jan 20, 2025
1 parent 3b4a2cc commit 57bc0de
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']

steps:
- uses: actions/checkout@v4
Expand Down
14 changes: 13 additions & 1 deletion pycardano/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,21 @@ def _restore_typed_primitive(
Union[:const:`Primitive`, CBORSerializable]: A CBOR primitive or a CBORSerializable.
"""

is_cbor_serializable = False
try:
is_cbor_serializable = issubclass(t, CBORSerializable)
except TypeError:
# Handle the case when t is a generic alias
origin = typing.get_origin(t)
if origin is not None:
try:
is_cbor_serializable = issubclass(origin, CBORSerializable)
except TypeError:
pass

if t is Any or (t in PRIMITIVE_TYPES and isinstance(v, t)):
return v
elif isclass(t) and issubclass(t, CBORSerializable):
elif is_cbor_serializable:
if "type_args" in getfullargspec(t.from_primitive).args:
args = typing.get_args(t)
return t.from_primitive(v, type_args=args)
Expand Down
18 changes: 0 additions & 18 deletions test/pycardano/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,24 +622,6 @@ def test_ordered_set_with_complex_types():
vkey_witnesses=NonEmptyOrderedSet[VerificationKeyWitness]([witness])
)

# # Deserialize an OrderedSet[int]
# data = [1, 2, 3]
# ordered_set = OrderedSet[int].from_primitive(data)
# print(ordered_set) # Output: OrderedSet([1, 2, 3])
#
# # Deserialize an OrderedSet[MyCBORClass]
# class MyCBORClass(ArrayCBORSerializable):
# a: int
#
# @dataclass
# class MyCBORClass2(ArrayCBORSerializable):
# a: OrderedSet[MyCBORClass]
#
#
# data = [{(1,), (2,)}]
# ordered_set = MyCBORClass2.from_primitive(data)
# print(ordered_set) # Output: OrderedSet([MyCBORClass(), MyCBORClass()])

# Test serialization/deserialization
primitive = witness_set.to_primitive()
restored = TransactionWitnessSet.from_primitive(primitive)
Expand Down

0 comments on commit 57bc0de

Please sign in to comment.