Skip to content

Commit 67a215c

Browse files
committed
fix: add version check for member import for Python 3.13
1 parent cde9f05 commit 67a215c

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

pycardano/backend/cardano_cli.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
Value,
4545
)
4646
from pycardano.types import JsonDict
47+
from pycardano.utils import greater_than_version
48+
49+
if greater_than_version((3, 13)):
50+
from enum import member # type: ignore[attr-defined]
51+
4752

4853
__all__ = ["CardanoCliChainContext", "CardanoCliNetwork", "DockerConfig"]
4954

@@ -70,7 +75,11 @@ class CardanoCliNetwork(Enum):
7075
PREVIEW = ["--testnet-magic", str(2)]
7176
PREPROD = ["--testnet-magic", str(1)]
7277
GUILDNET = ["--testnet-magic", str(141)]
73-
CUSTOM = partial(network_magic)
78+
CUSTOM = (
79+
member(partial(network_magic))
80+
if greater_than_version((3, 13))
81+
else partial(network_magic)
82+
)
7483

7584

7685
class DockerConfig:

pycardano/utils.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from __future__ import annotations
44

55
import math
6-
from typing import Dict, List, Optional, Union
6+
import sys
7+
from typing import Dict, List, Optional, Union, Tuple
78

89
import cbor2
910
from nacl.encoding import RawEncoder
@@ -24,6 +25,7 @@
2425
"min_lovelace_post_alonzo",
2526
"script_data_hash",
2627
"tiered_reference_script_fee",
28+
"greater_than_version",
2729
]
2830

2931

@@ -266,3 +268,15 @@ def script_data_hash(
266268
encoder=RawEncoder,
267269
)
268270
)
271+
272+
273+
def greater_than_version(version: Tuple[int, int]) -> bool:
274+
"""Check if the current Python version is greater than or equal to the specified version
275+
276+
Args:
277+
version (Tuple[int, int]): Tuple of major and minor version
278+
279+
Returns:
280+
True if the current Python version is greater than or equal to the specified version
281+
"""
282+
return sys.version_info >= version

0 commit comments

Comments
 (0)