Skip to content

Commit 57bc0de

Browse files
committed
Fix failed tests in ^3.11
1 parent 3b4a2cc commit 57bc0de

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
matrix:
1616
os: [ubuntu-latest, macos-latest]
17-
python-version: ['3.8', '3.9', '3.10', '3.11']
17+
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
1818

1919
steps:
2020
- uses: actions/checkout@v4

pycardano/serialization.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,21 @@ def _restore_typed_primitive(
543543
Union[:const:`Primitive`, CBORSerializable]: A CBOR primitive or a CBORSerializable.
544544
"""
545545

546+
is_cbor_serializable = False
547+
try:
548+
is_cbor_serializable = issubclass(t, CBORSerializable)
549+
except TypeError:
550+
# Handle the case when t is a generic alias
551+
origin = typing.get_origin(t)
552+
if origin is not None:
553+
try:
554+
is_cbor_serializable = issubclass(origin, CBORSerializable)
555+
except TypeError:
556+
pass
557+
546558
if t is Any or (t in PRIMITIVE_TYPES and isinstance(v, t)):
547559
return v
548-
elif isclass(t) and issubclass(t, CBORSerializable):
560+
elif is_cbor_serializable:
549561
if "type_args" in getfullargspec(t.from_primitive).args:
550562
args = typing.get_args(t)
551563
return t.from_primitive(v, type_args=args)

test/pycardano/test_serialization.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -622,24 +622,6 @@ def test_ordered_set_with_complex_types():
622622
vkey_witnesses=NonEmptyOrderedSet[VerificationKeyWitness]([witness])
623623
)
624624

625-
# # Deserialize an OrderedSet[int]
626-
# data = [1, 2, 3]
627-
# ordered_set = OrderedSet[int].from_primitive(data)
628-
# print(ordered_set) # Output: OrderedSet([1, 2, 3])
629-
#
630-
# # Deserialize an OrderedSet[MyCBORClass]
631-
# class MyCBORClass(ArrayCBORSerializable):
632-
# a: int
633-
#
634-
# @dataclass
635-
# class MyCBORClass2(ArrayCBORSerializable):
636-
# a: OrderedSet[MyCBORClass]
637-
#
638-
#
639-
# data = [{(1,), (2,)}]
640-
# ordered_set = MyCBORClass2.from_primitive(data)
641-
# print(ordered_set) # Output: OrderedSet([MyCBORClass(), MyCBORClass()])
642-
643625
# Test serialization/deserialization
644626
primitive = witness_set.to_primitive()
645627
restored = TransactionWitnessSet.from_primitive(primitive)

0 commit comments

Comments
 (0)